38 #ifndef _clib_included_socket_h 39 #define _clib_included_socket_h 41 #include <sys/types.h> 42 #include <sys/socket.h> 43 #include <netinet/in.h> 49 typedef struct _socket_t {
57 #define SOCKET_IS_SERVER (1 << 0) 58 #define SOCKET_IS_CLIENT (0 << 0) 59 #define SOCKET_NON_BLOCKING_CONNECT (1 << 1) 62 #define SOCKET_RX_END_OF_FILE (1 << 2) 71 struct sockaddr_in peer;
74 clib_error_t * (* read_func) (
struct _socket_t * sock,
int min_bytes);
100 vec_add2 (s->tx_buffer, result, n_bytes);
106 { s->tx_buffer =
va_format (s->tx_buffer, fmt, va); }
110 {
return s->write_func (s); }
114 {
return s->read_func (s, n_bytes); }
123 memset (s, 0,
sizeof (s[0]));
130 err = (* sock->close_func) (sock);
always_inline int clib_socket_rx_end_of_file(clib_socket_t *s)
#define vec_add2(V, P, N)
Add N elements to end of vector V, return pointer to new elements in P.
#define SOCKET_RX_END_OF_FILE
always_inline clib_error_t * clib_socket_tx(clib_socket_t *s)
always_inline void clib_socket_tx_add_va_formatted(clib_socket_t *s, char *fmt, va_list *va)
static clib_error_t * tx_buffer(void *transport, mc_transport_type_t type, u32 buffer_index)
struct _socket_t clib_socket_t
always_inline clib_error_t * clib_socket_close(clib_socket_t *sock)
always_inline uword clib_socket_is_server(clib_socket_t *sock)
always_inline uword clib_socket_is_client(clib_socket_t *s)
#define vec_free(V)
Free vector's memory (no header).
clib_error_t * clib_socket_accept(clib_socket_t *server, clib_socket_t *client)
always_inline void clib_socket_free(clib_socket_t *s)
always_inline uword clib_mem_is_heap_object(void *p)
always_inline clib_error_t * clib_socket_rx(clib_socket_t *s, int n_bytes)
clib_error_t * clib_socket_init(clib_socket_t *socket)
always_inline void * clib_socket_tx_add(clib_socket_t *s, int n_bytes)
void clib_socket_tx_add_formatted(clib_socket_t *s, char *fmt,...)