Operation Details

Top  Previous  Next

The SOCK library maintains a list of free and occupied sockets. This is kept in the sock_in_use array. You can see this array's contents under the debugger. To get a free socket (number), call sock_get() and it will return a socket number, which will now be marked as used. The function will return 255 if there are no free sockets left, so watch out for this number!

When calling sock_get(), you can supply a meaningful short name of the caller. For example, if the socket is to be used for TELNET-style communications with the device, set the signature to "TLNT". The sock_user_signature array keeps the signatures left by sock_get() callers. Observing this array's contents under the debugger will provide a clear picture of who is using which socket. The signature of free sockets is "-". Note that SOCK_MAX_SIGNATURE_LEN defines maximum signature length and the default value is 0. Set this to anything above 0 to be able to observe the signatures. You can set it back to 0 when the debugging process is over.

Another way to observe the operation of the library in the debug mode is by adding #define SOCK_DEBUG_PRINT 1 to the defines section of the global.tbh file of your project. A wealth of status information will be printed in the console pane as the SOCK library operates.

To release the socket, call sock_release(). This will mark the socket as free and the next caller of the sock_get() will have a chance to reuse this socket number. Additionally, the socket will be "cleaned up for reuse". Any socket connection in progress will be discarded (with sock.discard) and each property will be returned to its original, post-reset value.

Sock_who_uses() returns a signature left by the specified socket's user. This function doesn't have to be used and exists only for convenience.