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.

Starterware/PROCESSOR-SDK-AM335X: BSD socket example

Part Number: PROCESSOR-SDK-AM335X

Tool/software: Starterware

Hello,

I am trying to compile a simple BSD socket based program.  As the NDK documentation states in section 3.3  (3.3.1.1), I have placed all the separate BSD calls in a different source module and I am attempting to compile it.

I am using CCS 7.2, with pdk_am335x_1_0_7   and ndk_2_25_01_11

My call to "socket()" always returns -1.  It appears I need a call to "fdOpenSession" prior to creating the socket.

That function is not a BSD call, but I found it in bsd/socketndk.h.  Next up, it has an argument of the current task handle.  Specifically the call in the examples code segment is 

fdOpenSession(TaskSelf());

Well, "TaskSelf" comes from osif.h, which is littered with HANDLE, UNIT32, and other things like that.

In order to define them, it becomes necessary to include usertype.h.   Well, then that has it's own definition of IP6N which gives me a bunch of errors re-defining it.

Section 3.1.2.1 clearly says that the call to fdSessionOpen should be inside the task.  And the small code listing shows that "SOCKET s;"  is coexisting with "dfOpenSession".   However, there is no mention of how to #include the header files to get things to compile (and factor I find lacking all over the documentation) 

So then...  How are you supposed to get this to compile when there are conflicting types of the same name, spread across multiple header files, where there were not protected with #ifdefs ?

There is no BSD based socket examples I can find.   And advice is appreciated.

-CSW

 

  • The RTOS team have been notified. They will respond here.
  • Chris,

    Have you tried to add '-D_POSIX_SOURCE' in CCS Build->GNU Compiler->Symbols? see the BSD socket include error discussion here: 

    Is it possible to post your project here so I can reproduce the issue?

    Regards,
    Garrett

  • Garrett,

    Those links don't work.  In fact the text indicates it's a personal account, I can't open it.

    Adding _POSIX_SOURCE made it worse.  It went from what I describe below to 50+ undefined  "uint" 's  and other stuff I didn't bother to dig through.

    I don't want to post the whole project, and there is no point in it.  Just try to compile this:

    #include <stdio.h>
    #include <string.h>
    #include <stdlib.h>
    #include <ctype.h>
    #include <xdc/std.h>
    #include <xdc/runtime/Error.h>
    #include <xdc/runtime/System.h>
    #include <ti/sysbios/BIOS.h>
    #include <ti/sysbios/knl/Task.h>
    #include <ti/sysbios/knl/Semaphore.h>
    
    #include <xdc/cfg/global.h>
    
    #include <ti/ndk/inc/usertype.h>
    
    #include <socketndk.h>
    #include <sys/socket.h>
    
    #include <ti/ndk/inc/os/osif.h>

    Yes, there is no source code.  There doesn't need to be, this will generate a bunch of conflicting types.

    In other words, the message to TI is: "Your header files don't work with your header files."

    Specifically  :

    C:/ti/ndk_2_25_01_11/packages/ti/ndk/inc/bsd/sys/socket.h:85:16: error: redefinition of 'struct IP6N'
    typedef struct IP6N
    ^
    In file included from ../HTTP/HttpCxn.cpp:20:0:
    C:/ti/ndk_2_25_01_11/packages/ti/ndk/inc/usertype.h:62:16: error: previous definition of 'struct IP6N'
    typedef struct IP6N
    ^
    In file included from ../HTTP/HttpCxn.cpp:30:0:
    C:/ti/ndk_2_25_01_11/packages/ti/ndk/inc/bsd/sys/socket.h:93:6: error: invalid type in declaration before ';' token
    }IP6N;
    ^
    C:/ti/ndk_2_25_01_11/packages/ti/ndk/inc/bsd/sys/socket.h:93:6: error: conflicting declaration 'typedef int IP6N'
    In file included from ../HTTP/HttpCxn.cpp:20:0:
    C:/ti/ndk_2_25_01_11/packages/ti/ndk/inc/usertype.h:70:2: note: previous declaration as 'typedef struct IP6N IP6N'
    }IP6N;
    ^

    I removed  #include <ti/ndk/inc/usertype.h>, and provided a handful of my own definitions and I can make it compile. It's a hack job. But it gets me past this failure.

    -CSW

  • Hi CSW,

    Christopher Weber said:

    That function is not a BSD call, but I found it in bsd/socketndk.h.  Next up, it has an argument of the current task handle.  Specifically the call in the examples code segment is 

    fdOpenSession(TaskSelf());

    Well, "TaskSelf" comes from osif.h, which is littered with HANDLE, UNIT32, and other things like that.

    The best approach at this point would be to call the SYS/BIOS kernel API directly, instead of going through the NDK OSAL:

    #include <ti/sysbios/knl/Task.h>
    
    ...
    
    fdOpenSession(Task_self());

    Steve

  • Steven Connell said:

    Hi CSW,

    Christopher Weber

    That function is not a BSD call, but I found it in bsd/socketndk.h.  Next up, it has an argument of the current task handle.  Specifically the call in the examples code segment is 

    fdOpenSession(TaskSelf());

    Well, "TaskSelf" comes from osif.h, which is littered with HANDLE, UNIT32, and other things like that.

    The best approach at this point would be to call the SYS/BIOS kernel API directly, instead of going through the NDK OSAL:

    #include <ti/sysbios/knl/Task.h>
    
    ...
    
    fdOpenSession(Task_self());

    Steve

    Steve. I already have that header file.

    If I remove "ti/ndk/inc/os/osif.h" then I get  "../HTTP/file.cpp:118:24: error: 'TaskSelf' was not declared in this scope "

    That is NOT the problem with your headerfiles.

    The problem is that "osif.h" needs "UINT8", "UNIT32",  "HANDLE" , and other things.

    But if I include "ti/ndk/inc/usertype.h"  in order to handle the requrements, I get " error: redefinition of 'struct IP6N'"  from "socket.h"

    This is the basic headers I have had to use:

    #include <stdio.h>
    #include <string.h>
    #include <stdlib.h>
    #include <ctype.h>
    #include <xdc/std.h>
    #include <xdc/runtime/Error.h>
    #include <xdc/runtime/System.h>
    #include <ti/sysbios/BIOS.h>
    #include <ti/sysbios/knl/Task.h>
    #include <ti/sysbios/knl/Semaphore.h>
    
    #include <xdc/cfg/global.h>
    
    #include <ti/ndk/inc/usertype.h>
    
    #include <sys/socket.h>
    
    #include <ti/ndk/inc/os/osif.h>
    
    void RunThread(UArg a0, UArg a1) {
    void * m_hTask; int result; m_hTask = TaskSelf(); fdOpenSession(m_hTask);
    //... other code }

    Specifically, this should be able to compile without TI headers stepping on each other.

    This, plus the fact that the USB drivers were rewritten and now there are no sample to build from for anything except "MSC", are just a few examples which shows this eco-system is not ready for prime time...