Main Page | Modules | Alphabetical List | Data Structures | File List | Data Fields | Globals | Related Pages

sockets.h File Reference


Detailed Description

Socket management.

Author:
Raphael Manfredi
Date:
2001-2003
Author:
Daniel Walker (dwalker@cats.ucsc.edu)
Date:
2000

#include "common.h"
#include "if/core/wrap.h"
#include "if/core/sockets.h"
#include "lib/inputevt.h"

Go to the source code of this file.

Data Structures

struct  gnutella_socket

Defines

#define SOCKET_WITH_TLS(s)   ((void) (s), 0)
#define SOCKET_USES_TLS(s)   ((void) (s), 0)
#define SOCK_F_ESTABLISHED   0x00000001 /**< Connection was established */
 Connection was established.

#define SOCK_F_EOF   0x00000002 /**< Got an EOF condition */
 Got an EOF condition.

#define SOCK_F_UDP   0x40000000 /**< Is a UDP socket */
 Is a UDP socket.

#define SOCK_F_TCP   0x80000000 /**< Is a TCP socket */
 Is a TCP socket.

#define sock_is_corked(x)   ((x)->corked)
 Access macros.

#define udp_active()   (enable_udp && NULL != s_udp_listen)
 This macro verifies whether UDP support is enabled and if the UDP socket has been initialized.


Enumerations

enum  socket_direction { SOCK_CONN_INCOMING, SOCK_CONN_OUTGOING, SOCK_CONN_LISTENING, SOCK_CONN_PROXY_OUTGOING }
enum  socket_type {
  SOCK_TYPE_UNKNOWN = 0, SOCK_TYPE_CONTROL, SOCK_TYPE_DOWNLOAD, SOCK_TYPE_UPLOAD,
  SOCK_TYPE_HTTP, SOCK_TYPE_SHELL, SOCK_TYPE_CONNBACK, SOCK_TYPE_PPROXY,
  SOCK_TYPE_DESTROYING, SOCK_TYPE_UDP
}
 Connection types. More...


Functions

void socket_init (void)
void socket_register_fd_reclaimer (reclaim_fd_t callback)
 Register fd reclaiming callback.

void socket_eof (struct gnutella_socket *s)
 Got an EOF condition on the socket.

void socket_free (struct gnutella_socket *)
 Dispose of socket, closing connection, removing input callback, and reclaiming attached getline buffer.

gnutella_socketsocket_connect (const host_addr_t, guint16, enum socket_type, guint32 flags)
 Creates a connected socket with an attached resource of `type'.

gnutella_socketsocket_connect_by_name (const gchar *host, guint16, enum socket_type, guint32 flags)
 Like socket_connect() but the remote address is not known and must be resolved through async DNS calls.

gnutella_socketsocket_tcp_listen (const host_addr_t, guint16, enum socket_type)
 Creates a non-blocking TCP listening socket with an attached resource of `type'.

gnutella_socketsocket_udp_listen (const host_addr_t, guint16)
 Creates a non-blocking listening UDP socket.

void socket_evt_set (struct gnutella_socket *s, inputevt_cond_t cond, inputevt_handler_t handler, gpointer data)
 Install handler callback when an input condition is satisfied on the socket.

void socket_evt_clear (struct gnutella_socket *s)
 Remove I/O readiness monitoring on the socket.

void sock_cork (struct gnutella_socket *s, gboolean on)
 Set/clear TCP_CORK on the socket.

void sock_send_buf (struct gnutella_socket *s, gint size, gboolean shrink)
 Set socket's send buffer to specified size.

void sock_recv_buf (struct gnutella_socket *s, gint size, gboolean shrink)
 Set socket's receive buffer to specified size.

void sock_nodelay (struct gnutella_socket *s, gboolean on)
 Turn TCP_NODELAY on or off on the socket.

void sock_tx_shutdown (struct gnutella_socket *s)
 Shutdown the TX side of the socket.

void socket_tos_default (const struct gnutella_socket *s)
void socket_tos_throughput (const struct gnutella_socket *s)
 Set the Type of Service (TOS) field to "throughput." This may cause your host and/or any routers along the path to put its packets in a lower-priority queue, and/or to route them along the highest- bandwidth path without regard for latency.

void socket_tos_lowdelay (const struct gnutella_socket *s)
 Set the Type of Service (TOS) field to "lowdelay." This may cause your host and/or any routers along the path to put its packets in a higher-priority queue, and/or to route them along the lowest- latency path without regard for bandwidth.

void socket_tos_normal (const struct gnutella_socket *s)
 Set the Type of Service (TOS) field to "normal.".

gboolean socket_bad_hostname (struct gnutella_socket *s)
void socket_timer (time_t now)
 Called by main timer.

void socket_shutdown (void)
 Cleanup data structures on shutdown.

ssize_t safe_readv (wrap_io_t *wio, struct iovec *iov, gint iovcnt)
 Wrapper over readv() ensuring that we don't request more than MAX_IOV_COUNT entries at a time.

ssize_t safe_writev (wrap_io_t *wio, struct iovec *iov, gint iovcnt)
 Wrapper over writev() ensuring that we don't request more than MAX_IOV_COUNT entries at a time.

ssize_t safe_writev_fd (gint fd, struct iovec *iov, gint iovcnt)
 Wrapper over writev() ensuring that we don't request more than MAX_IOV_COUNT entries at a time.


Variables

gnutella_sockets_tcp_listen
gnutella_sockets_udp_listen


Define Documentation

#define SOCK_F_EOF   0x00000002 /**< Got an EOF condition */
 

Got an EOF condition.

#define SOCK_F_ESTABLISHED   0x00000001 /**< Connection was established */
 

Connection was established.

#define SOCK_F_TCP   0x80000000 /**< Is a TCP socket */
 

Is a TCP socket.

#define SOCK_F_UDP   0x40000000 /**< Is a UDP socket */
 

Is a UDP socket.

#define sock_is_corked  )     ((x)->corked)
 

Access macros.

#define SOCKET_USES_TLS s   )     ((void) (s), 0)
 

#define SOCKET_WITH_TLS s   )     ((void) (s), 0)
 

 
#define udp_active  )     (enable_udp && NULL != s_udp_listen)
 

This macro verifies whether UDP support is enabled and if the UDP socket has been initialized.


Enumeration Type Documentation

enum socket_direction
 

Enumeration values:
SOCK_CONN_INCOMING 
SOCK_CONN_OUTGOING 
SOCK_CONN_LISTENING 
SOCK_CONN_PROXY_OUTGOING 

enum socket_type
 

Connection types.

Enumeration values:
SOCK_TYPE_UNKNOWN 
SOCK_TYPE_CONTROL 
SOCK_TYPE_DOWNLOAD 
SOCK_TYPE_UPLOAD 
SOCK_TYPE_HTTP 
SOCK_TYPE_SHELL 
SOCK_TYPE_CONNBACK 
SOCK_TYPE_PPROXY 
SOCK_TYPE_DESTROYING 
SOCK_TYPE_UDP 


Function Documentation

ssize_t safe_readv wrap_io_t wio,
struct iovec *  iov,
gint  iovcnt
 

Wrapper over readv() ensuring that we don't request more than MAX_IOV_COUNT entries at a time.

ssize_t safe_writev wrap_io_t wio,
struct iovec *  iov,
gint  iovcnt
 

Wrapper over writev() ensuring that we don't request more than MAX_IOV_COUNT entries at a time.

ssize_t safe_writev_fd gint  fd,
struct iovec *  iov,
gint  iovcnt
 

Wrapper over writev() ensuring that we don't request more than MAX_IOV_COUNT entries at a time.

void sock_cork struct gnutella_socket s,
gboolean  on
 

Set/clear TCP_CORK on the socket.

When set, TCP will only send out full TCP/IP frames. The exact size depends on your LAN interface, but on Ethernet, it's about 1500 bytes.

void sock_nodelay struct gnutella_socket s,
gboolean  on
 

Turn TCP_NODELAY on or off on the socket.

void sock_recv_buf struct gnutella_socket s,
gint  size,
gboolean  shrink
 

Set socket's receive buffer to specified size.

If `shrink' is false, refuse to shrink the buffer if its size is larger.

void sock_send_buf struct gnutella_socket s,
gint  size,
gboolean  shrink
 

Set socket's send buffer to specified size.

If `shrink' is false, refuse to shrink the buffer if its size is larger.

void sock_tx_shutdown struct gnutella_socket s  ) 
 

Shutdown the TX side of the socket.

gboolean socket_bad_hostname struct gnutella_socket s  ) 
 

Returns:
whether bad hostname was reported after a DNS lookup.

struct gnutella_socket* socket_connect const host_addr_t  ha,
guint16  port,
enum socket_type  type,
guint32  flags
 

Creates a connected socket with an attached resource of `type'.

Connection happens in the background, the connection callback being determined by the resource type.

struct gnutella_socket* socket_connect_by_name const gchar *  host,
guint16  ,
enum  socket_type,
guint32  flags
 

Like socket_connect() but the remote address is not known and must be resolved through async DNS calls.

void socket_eof struct gnutella_socket s  ) 
 

Got an EOF condition on the socket.

void socket_evt_clear struct gnutella_socket s  ) 
 

Remove I/O readiness monitoring on the socket.

void socket_evt_set struct gnutella_socket s,
inputevt_cond_t  cond,
inputevt_handler_t  handler,
gpointer  data
 

Install handler callback when an input condition is satisfied on the socket.

Parameters:
s the socket
cond Any INPUT_EVENT_* except INPUT_EVENT_EXCEPTION.
handler the handler callback to invoke when condition is satisfied
data opaque data to supply to the callback
Note:
When monitoring for INPUT_EVENT_RW(X), both INPUT_EVENT_R and INPUT_EVENT_W flags can be set at the same time when the callback is invoked.

void socket_free struct gnutella_socket  ) 
 

Dispose of socket, closing connection, removing input callback, and reclaiming attached getline buffer.

void socket_init void   ) 
 

void socket_register_fd_reclaimer reclaim_fd_t  callback  ) 
 

Register fd reclaiming callback.

Use NULL to unregister it.

void socket_shutdown void   ) 
 

Cleanup data structures on shutdown.

struct gnutella_socket* socket_tcp_listen const  host_addr_t,
guint16  ,
enum  socket_type
 

Creates a non-blocking TCP listening socket with an attached resource of `type'.

void socket_timer time_t  now  ) 
 

Called by main timer.

Expires inactive sockets.

void socket_tos_default const struct gnutella_socket s  ) 
 

void socket_tos_lowdelay const struct gnutella_socket s  ) 
 

Set the Type of Service (TOS) field to "lowdelay." This may cause your host and/or any routers along the path to put its packets in a higher-priority queue, and/or to route them along the lowest- latency path without regard for bandwidth.

void socket_tos_normal const struct gnutella_socket s  ) 
 

Set the Type of Service (TOS) field to "normal.".

void socket_tos_throughput const struct gnutella_socket s  ) 
 

Set the Type of Service (TOS) field to "throughput." This may cause your host and/or any routers along the path to put its packets in a lower-priority queue, and/or to route them along the highest- bandwidth path without regard for latency.

struct gnutella_socket* socket_udp_listen const  host_addr_t,
guint16 
 

Creates a non-blocking listening UDP socket.


Variable Documentation

struct gnutella_socket* s_tcp_listen
 

struct gnutella_socket* s_udp_listen
 


Generated on Sun Feb 12 10:50:08 2006 for Gtk-Gnutella by doxygen 1.3.6