src/net.c File Reference
Portable non-blocking TCP network functions.
More...
Functions |
bool | net_socket_make_nonblocking (evutil_socket_t sock) |
| Make the given socket non-blocking.
|
bool | net_module_init (void) |
| Initialise the network module.
|
void | net_module_close (void) |
| Close the network module.
|
bool | net_socket_create (evutil_socket_t *sock) |
| Create a new non-blocking IP streaming socket.
|
void | net_socket_close (evutil_socket_t sock) |
| Gracefully close the given socket both ways.
|
bool | net_socket_listen (evutil_socket_t sock, int backlog) |
| Start listening on the given socket.
|
bool | net_socket_bind (evutil_socket_t sock, const unsigned short int port) |
| Bind the specified socket to the given port.
|
bool | net_socket_accept (evutil_socket_t sock, evutil_socket_t *client) |
| Accept on the given socket.
|
net_recv_result_e | net_recv (evutil_socket_t sock, void *data, const size_t n, size_t *bytesRead) |
| Receive data from the given socket.
|
net_send_result_e | net_send (evutil_socket_t sock, const void *data, const size_t n, size_t *bytesSent) |
| Send data on the given socket.
|
bool | net_connect (evutil_socket_t *sock, const unsigned short int port) |
| Connect to a given address.
|
h_uint16_t | net_ntohs (h_uint16_t netShort) |
| Convert from network short to host short.
|
Detailed Description
Portable non-blocking TCP network functions.
- Date:
- 17 Jan 2010
- Author:
- Zachary Sims <zacs7@users.sourceforge.net>
Module prefix: net_
$Id$
Function Documentation
bool net_connect |
( |
evutil_socket_t * |
sock, |
|
|
const unsigned short int |
port | |
|
) |
| | |
Connect to a given address.
- Parameters:
-
| sock | The socket to set once we've connected. |
| port | The port to connect on. |
- Returns:
- true if we connected (or already connected). On error, false is returned.
void net_module_close |
( |
void |
|
) |
|
bool net_module_init |
( |
void |
|
) |
|
Initialise the network module.
Call before using any other net_ functions.
- See also:
- net_module_close()
- Returns:
true
on success. On error, false
is returned
Convert from network short to host short.
- Parameters:
-
| netShort | The network short to convert to host short byte order. |
- Returns:
- The short in host byte order.
net_recv_result_e net_recv |
( |
evutil_socket_t |
sock, |
|
|
void * |
data, |
|
|
const size_t |
n, |
|
|
size_t * |
bytesRead | |
|
) |
| | |
Receive data from the given socket.
- Parameters:
-
| sock | The connected socket to receive on. |
| data | Where to put the bytes. |
| n | The number of bytes to read. |
| bytesRead | Where to put the number of bytes read. |
- Returns:
- a net_recv_result_e return code.
net_send_result_e net_send |
( |
evutil_socket_t |
sock, |
|
|
const void * |
data, |
|
|
const size_t |
n, |
|
|
size_t * |
bytesSent | |
|
) |
| | |
Send data on the given socket.
- Parameters:
-
| sock | The connected socket to send on. |
| data | Where to get the bytes. |
| n | The number of bytes to send. |
| bytesSent | Where to put the number of bytes sent. |
- Returns:
- a net_send_result_e return code.
bool net_socket_accept |
( |
evutil_socket_t |
sock, |
|
|
evutil_socket_t * |
client | |
|
) |
| | |
Accept on the given socket.
- Parameters:
-
| sock | The socket to accept on. |
| client | The socket that was accepted if true is returned. Should be closed when you're finished. The socket is non-blocking. |
- Returns:
true
if we've accepted a socket into newSock. On error, false
is returned.
bool net_socket_bind |
( |
evutil_socket_t |
sock, |
|
|
const unsigned short int |
port | |
|
) |
| | |
Bind the specified socket to the given port.
- Parameters:
-
| sock | The socket to bind. |
| port | The port to bind to. |
- Returns:
true
if we're now bound. On error, false
is returned.
void net_socket_close |
( |
evutil_socket_t |
sock |
) |
|
Gracefully close the given socket both ways.
- See also:
- net_socket_create()
- Parameters:
-
| sock | The address of the socket to close. |
- Todo:
- don't "shutdown" if the socket is invalid
bool net_socket_create |
( |
evutil_socket_t * |
sock |
) |
|
Create a new non-blocking IP streaming socket.
- See also:
- net_socket_close()
- Parameters:
-
| sock | The address of the socket to create. |
- Returns:
true
on success. On error, false
is returned
bool net_socket_listen |
( |
evutil_socket_t |
sock, |
|
|
int |
backlog | |
|
) |
| | |
Start listening on the given socket.
- Parameters:
-
| sock | The socket to listen on. |
| backlog | The number of connections to backlog. |
- Returns:
true
if we're now listening on the socket. On error, false
is returned.
bool net_socket_make_nonblocking |
( |
evutil_socket_t |
sock |
) |
|
Make the given socket non-blocking.
- Parameters:
-
| sock | The socket to make non-blocking. |
- Returns:
true
if the socket is now non-blocking. On error, false
is returned.