On 9 April 2014 16:59, Sean P. DeNigris <sean@clipperadams.com> wrote:
How do Socket handles map to C socket IDs? I'm wrapping libssh2 via Native
Boost and I'd much rather create sockets via Smalltalk than C, but I'm not
sure how to pass the handle to a C function expecting a C socket ID. Maybe
I'm missing something really simple? Thanks.


socket plugin using own data structure for socket handles,
it includes different kind of internal information, including OS-specific socket handle.
��
typedef struct
{
�� int���� sessionID;
�� int���� socketType;�� /* 0 = TCP, 1 = UDP */
�� void�� *privateSocketPtr;
}�� SQSocket, *SocketPtr;

extracting the OS-specific handle could be problematic, since it is in
that opaque void�� *privateSocketPtr; field.

Then:

sqUnixSocket.c

typedef struct privateSocketStruct
{
�� int s;������ ������ ������ /* Unix socket */
�� int connSema;������ ������ ������ /* connection io notification semaphore */
�� int readSema;������ ������ ������ /* read io notification semaphore */
�� int writeSema;������ ������ /* write io notification semaphore */
�� int sockState;������ ������ /* connection + data state */
�� int sockError;������ ������ /* errno after socket error */
�� union sockaddr_any peer;������ /* default send/recv address for UDP */
�� socklen_t peerSize;������ ������ /* dynamic sizeof(peer) */
�� union sockaddr_any sender;������ /* sender address for last UDP receive */
�� socklen_t senderSize;������ ������ /* dynamic sizeof(sender) */
�� int multiListen;������ ������ /* whether to listen for multiple connections */
�� int acceptedSock;������ ������ /* a connection that has been accepted */
} privateSocketStruct;


so, to extract OS-level socked handle *on unix*, you have to

handle = ( (privateSocketStruct*) sqsocket.privateSocketPtr) -> s.

where sqsocket is SQSocket.


there's even macros for that:

/*** Accessors for private socket members from a Squeak socket pointer ***/

#define _PSP(S)������ ������ (((S)->privateSocketPtr))
#define PSP(S)������ ������ ((privateSocketStruct *)((S)->privateSocketPtr))

#define SOCKET(S)������ ������ (PSP(S)->s)
#define SOCKETSTATE(S)������ ������ (PSP(S)->sockState)
#define SOCKETERROR(S)������ ������ (PSP(S)->sockError)
#define SOCKETPEER(S)������ ������ (PSP(S)->peer)
#define SOCKETPEERSIZE(S)������ (PSP(S)->peerSize)



-----
Cheers,
Sean
--
View this message in context: http://forum.world.st/Socket-Handles-to-C-tp4753619.html
Sent from the Pharo Smalltalk Users mailing list archive at Nabble.com.




--
Best regards,
Igor Stasenko.