|
These functions handle exchange of data with other hosts via the Internet Protocol.
|
GWENHYWFAR_API int | GWEN_Socket_Read (GWEN_SOCKET *sp, char *buffer, int *bsize) |
|
GWENHYWFAR_API int | GWEN_Socket_Write (GWEN_SOCKET *sp, const char *buffer, int *bsize) |
|
GWENHYWFAR_API int | GWEN_Socket_ReadFrom (GWEN_SOCKET *sp, GWEN_INETADDRESS **addr, char *buffer, int *bsize) |
|
GWENHYWFAR_API int | GWEN_Socket_WriteTo (GWEN_SOCKET *sp, const GWEN_INETADDRESS *addr, const char *buffer, int *bsize) |
|
This group operates on IP sockets.
◆ GWEN_Socket_Accept()
This accepts a new connection on the given socket. This socket must be listening (achieved by calling GWEN_Socket_Listen).
- Parameters
-
sp | socket which is listening |
addr | pointer to a pointer to an address. Upon return this pointer will point to a newly allocated address containing the address of the connected peer. Please note that if upon return this value is !=NULL then you are responsible for freeing this address ! |
newsock | pointer to a pointer to a socket. Upon return this holds the pointer to a newly allocated socket. Please note that if upon return this value is !=NULL then you are responsible for freeing this socket ! |
◆ GWEN_Socket_Bind()
◆ GWEN_Socket_Close()
Unarms a socket thus closing any connection associated with this socket.
◆ GWEN_Socket_Connect()
◆ GWEN_Socket_free()
◆ GWEN_Socket_fromFile()
◆ GWEN_Socket_GetPeerAddr()
Retrieves the peer's address
- Parameters
-
sp | socket |
addr | pointer to a pointer to an GWEN_INETADDRESS. Upon successful return that pointer will point to the address of the peer. In that case the caller is responsible for freeing that address. |
◆ GWEN_Socket_GetSocketError()
Returns a pending socket error. This is used when trying to connect to a server when in non-blocking mode. In this case the connect call will in some cases return with an error code indicating that the connect is in progress. Later you will then need to find out whether that connect succeeded or not. And this is the function which can tell you that ;-)
- Parameters
-
◆ GWEN_Socket_GetSocketInt()
This function should only be used if it is absolutely necessary, because it might not be supported by every system. However, it is currently supported by all systems on which the Berkeley Socket API is used (e.g. most if not all POSIX systems, in this implementation also WIN32). What you can do with the value returned depends very much on the underlying operating system. For POSIX systems the value returned is just a file handle as returned by e.g. socket().
◆ GWEN_Socket_GetSocketType()
Returns the socket type.
- Parameters
-
◆ GWEN_Socket_Listen()
◆ GWEN_Socket_new()
Constructor. You should always use this to create socket variables.
◆ GWEN_Socket_Open()
Arms the socket so that it can be used. This really creates a system socket.
◆ GWEN_Socket_Read()
Read bytes from a socket. This function might return GWEN_ERROR_INTERRUPTED in case the read request was interrupted by a posix signal or GWEN_ERROR_TIMEOUT on non-blocking sockets which have currently no data available.
- Parameters
-
sp | socket |
buffer | pointer to the buffer to receive the data |
bsize | pointer to an integer variable. Upon call this should hold the number of bytes to read, upon return it will contain the number of bytes actually read. |
◆ GWEN_Socket_ReadFrom()
Reads bytes from an UDP socket, which is connectionless.
- Parameters
-
sp | socket |
addr | pointer to pointer to an address to receive the address of the peer we have received data from. Please note that if upon return this value is !=NULL then you are responsible for freeing this address ! |
buffer | pointer to a buffer to store the received data in |
bsize | pointer to an integer variable. Upon call this should hold the number of bytes to read, upon return it will contain the number of bytes actually read. |
◆ GWEN_Socket_Select()
This function waits for a group of sockets to change their state.
- Parameters
-
rs | socket set, wait for readability of those sockets |
ws | socket set, wait for writeability of those sockets |
xs | socket set, wait for "exceptional events" on those sockets |
timeout | time to wait in milliseconds. If <0 then this function will wait forever, if ==0 then it won't wait at all. |
◆ GWEN_Socket_SetBlocking()
Toggles the sockets blocking/non-blocking mode.
- Parameters
-
sp | socket |
fl | if 0 then nonblocking is requested, otherwise blocking is assumed |
◆ GWEN_Socket_SetBroadcast()
Toggles the sockets broadcast/non-broadcast mode. If in broadcast mode (for UDP sockets only) the socket is able to receive packets that have been sent to a broadcast address, otherwise those packets are ignored.
- Parameters
-
sp | socket |
fl | if nonzero then broadcast is enabled |
◆ GWEN_Socket_SetReuseAddress()
Normally after closing a socket the occupied TCP/UDP port will be unavailable for another call to the system function bind (2). If reusing is allowed then this latency is removed. This function is usefull for servers.
- Parameters
-
sp | socket |
fl | if nonzero then reusing the address is enabled |
◆ GWEN_Socket_WaitForRead()
Wait until the given socket becomes readable or a timeout occurrs.
- Parameters
-
◆ GWEN_Socket_WaitForWrite()
Wait until the given socket becomes writeable or a timeout occurrs.
- Parameters
-
◆ GWEN_Socket_Write()
Write bytes to an open socket.
- Parameters
-
sp | socket |
buffer | pointer to a buffer containing the bytes to be written |
bsize | pointer to an integer variable containing the number of bytes to write. Upon return this variable holds the number of bytes actually written. Please note that this function may write less bytes than expected! |
◆ GWEN_Socket_WriteTo()
Writes data to an UDP socket, which is connectionless.
- Parameters
-
sp | socket |
addr | pointer to the address struct specifying the recipient |
buffer | pointer to a buffer containing the bytes to be written |
bsize | pointer to an integer variable containing the number of bytes to write. Upon return this variable holds the number of bytes actually written. Please note that this function may write less bytes than expected! |