1
Programming / Re: Networking: socket() returns positive `non-socket`
« on: July 07, 2025, 10:31:59 pm »
Are your C functions statically linked into agena.exe? It's not clear from your example.
If your C functions are linked into agena.exe or are in a DLL linked to agena, baring defects, the code should work as you expect.
While sock only has a value during the function call, you have exported the value to L and I assume the exported value is global and persistent.
I recommend adding a bit of debugging code to printf the value of sock in both functions.
Just returning from a function call is not going to close the socket. The socket will stay open until explicitly closed by your code or when the executable terminates.
You can watch the state of the socket with netstat -s.
To understand how kLIBC maps sockets to file handles see:
src\emx\src\libsocket\socket.c:41
int socket(int af, int type, int protocol)
at
https://github.com/bitwiseworks/libc
If your C functions are linked into agena.exe or are in a DLL linked to agena, baring defects, the code should work as you expect.
While sock only has a value during the function call, you have exported the value to L and I assume the exported value is global and persistent.
I recommend adding a bit of debugging code to printf the value of sock in both functions.
Just returning from a function call is not going to close the socket. The socket will stay open until explicitly closed by your code or when the executable terminates.
You can watch the state of the socket with netstat -s.
To understand how kLIBC maps sockets to file handles see:
src\emx\src\libsocket\socket.c:41
int socket(int af, int type, int protocol)
at
https://github.com/bitwiseworks/libc