This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

creating socket in sub task?

Hi, I have a problem to create socket in a sub task, which is created in one of my task by calling TaskCreate. the following code shows the way how my code is organized.

void myNdkTask() //this task is created statically in the .cfg file
{
  ..............
  SOCKET s;
  s = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP);
  if(s == INVALID_SOCKET)
  {
    if(debug)
         printf("failed create socket (%d)\n", fdError());
    exit(1);
  }

   ..............
   void (*pTaskFxn)(int, int, int);
   pTaskFxn=subTaskFxn;
   TaskCreate(pTaskFxn, "subtask0", OS_TASKPRINORM, 2048, 0, 0, 0);

}

void subTaskFxn{}
{
   ..............

   SOCKET sub_socket;
   sub_socket = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP);
   if(sub_socket == INVALID_SOCKET)
   {
      if(debug)
           printf("failed create socket (%d)\n", fdError());
      exit(1);
    }
   ..................
}

when the program is executed, it always exit because of the fail of creating sub_socket, but the SOCKET s in myNdkTask() can return a VALID handle. can anyone helps me solve it or points out the problem that I have not noticed? thanks

  • Hi,

    There is no limit to the number of tasks that can be installed in the system. The only possible failure on TaskCreate() is a memory allocation error.

    If the priority level of the new task is higher than the priority level of the current task, the entry-point function pFun is executed immediately (before TaskCreate() returns to the caller).

    For correct stack operation, a task thread must open a file descriptor session before calling any file descriptor related functions, and then close it when it is done.

    When the task is finished using the file descriptor API, or when it is about to terminate, the function fdCloseSession() is called.

    This wiki help you for BIOS API based task creation
    http://processors.wiki.ti.com/images/9/97/Tasks.pdf