GEOS SDK TechDocs|
|
8 Closing the Connection |
10 Domain-Specific Information SocketCheckListen(), SocketCheckReady()
The Socket library provides utility routines that query the status of a connection. This can be helpful when figuring out why a connection may not be working or confirming that a connection is working.
Use
SocketCheckListen()
on a port to find out the domain and medium for the first connection request on the port; that is, the first connection request which has not yet been accepted. Think of this as a limited form of "caller ID" -- a chance to find out about the incoming connection before accepting it. If
SocketCheckListen()
returns SE_PORT_NOT_LISTENING, it means there is no socket that is bound to the port and listening.
To "peek" at the next packet of incoming data, call
SocketRecv()
and pass the SRF_PEEK flag. This allows you to get the size of the next packet of incoming data and to look at its contents without destroying it.
To check one or more sockets to see if they have received data, received connection requests, or are ready to write, call
SocketCheckReady()
. It can check connections for incoming data or just incoming urgent data.
For programs which need to poll many sockets,
SocketCheckReady()
provides a tidy means to do this without spawning a thread for each socket.
The
SocketCheckReady()
routine takes an array of
SocketCheckRequest
structures. Each one of these structures contains a socket and a condition.
SocketCheckReady()
looks at each
SocketCheckRequest
structure in the array and returns the index of the first structure whose socket meets the condition.
Thus, to determine if a given socket is properly set up so that you can send data through it, pass
SocketCheckReady()
a one-element array (represented in pseudo-code):
{ mySocket, SC_WRITE, 0 }
To check several sockets to see whether any of them had received any connection requests, pass to
SocketCheckReady()
an array of the form (represented in pseudo-code):
{ socket1, SC_ACCEPT, 0 },
{ socket2, SC_ACCEPT, 0 },
{ socket3, SC_ACCEPT, 0 }
For any socket, you may check for one or more of the following conditions, as represented by
SocketCondition
values:
If you query a socket about a condition that does not apply to its current state (
e.g.
, ask a non-listening socket if it is ready to accept connections), then
SocketCheckReady()
returns SE_IMPROPER_CONDITION.
GEOS SDK TechDocs|
|
8 Closing the Connection |
10 Domain-Specific Information