Skip to content

Commit

Permalink
Rename evnet to evcom.
Browse files Browse the repository at this point in the history
  • Loading branch information
ry committed Jul 25, 2009
1 parent 842eaf4 commit 0fb0af3
Show file tree
Hide file tree
Showing 12 changed files with 306 additions and 306 deletions.
188 changes: 94 additions & 94 deletions deps/evnet/evnet.c → deps/evcom/evcom.c

Large diffs are not rendered by default.

132 changes: 66 additions & 66 deletions deps/evnet/evnet.h → deps/evcom/evcom.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/* Copyright (c) 2008,2009 Ryan Dahl
*
* evnet_queue comes from Nginx, ngx_queue.h
* evcom_queue comes from Nginx, ngx_queue.h
* Copyright (C) 2002-2009 Igor Sysoev
*
* Redistribution and use in source and binary forms, with or without
Expand Down Expand Up @@ -28,102 +28,102 @@
#include <ev.h>
#include <stddef.h> /* offsetof() */

#ifndef evnet_h
#define evnet_h
#ifndef evcom_h
#define evcom_h

#ifdef __cplusplus
extern "C" {
#endif

#ifndef EVNET_HAVE_GNUTLS
# define EVNET_HAVE_GNUTLS 0
#ifndef EVCOM_HAVE_GNUTLS
# define EVCOM_HAVE_GNUTLS 0
#endif
#if EVNET_HAVE_GNUTLS
#if EVCOM_HAVE_GNUTLS
# include <gnutls/gnutls.h>
#endif

typedef struct evnet_queue evnet_queue;
typedef struct evnet_buf evnet_buf;
typedef struct evnet_server evnet_server;
typedef struct evnet_socket evnet_socket;
typedef struct evcom_queue evcom_queue;
typedef struct evcom_buf evcom_buf;
typedef struct evcom_server evcom_server;
typedef struct evcom_socket evcom_socket;

void evnet_server_init (evnet_server *);
int evnet_server_listen (evnet_server *, struct addrinfo *addrinfo, int backlog);
void evnet_server_attach (EV_P_ evnet_server *);
void evnet_server_detach (evnet_server *);
void evnet_server_close (evnet_server *); // synchronous
void evcom_server_init (evcom_server *);
int evcom_server_listen (evcom_server *, struct addrinfo *addrinfo, int backlog);
void evcom_server_attach (EV_P_ evcom_server *);
void evcom_server_detach (evcom_server *);
void evcom_server_close (evcom_server *); // synchronous

void evnet_socket_init (evnet_socket *, float timeout);
int evnet_socket_connect (evnet_socket *, struct addrinfo *addrinfo);
void evnet_socket_attach (EV_P_ evnet_socket *);
void evnet_socket_detach (evnet_socket *);
void evnet_socket_read_start (evnet_socket *);
void evnet_socket_read_stop (evnet_socket *);
void evcom_socket_init (evcom_socket *, float timeout);
int evcom_socket_connect (evcom_socket *, struct addrinfo *addrinfo);
void evcom_socket_attach (EV_P_ evcom_socket *);
void evcom_socket_detach (evcom_socket *);
void evcom_socket_read_start (evcom_socket *);
void evcom_socket_read_stop (evcom_socket *);

/* Resets the timeout to stay alive for another socket->timeout seconds
*/
void evnet_socket_reset_timeout (evnet_socket *);
void evcom_socket_reset_timeout (evcom_socket *);

/* Writes a buffer to the socket.
* (Do not send a NULL evnet_buf or a buffer with evnet_buf->base == NULL.)
* (Do not send a NULL evcom_buf or a buffer with evcom_buf->base == NULL.)
*/
void evnet_socket_write (evnet_socket *, evnet_buf *);
void evcom_socket_write (evcom_socket *, evcom_buf *);

void evnet_socket_write_simple (evnet_socket *, const char *str, size_t len);
void evcom_socket_write_simple (evcom_socket *, const char *str, size_t len);

/* Once the write buffer is drained, evnet_socket_close will shutdown the
/* Once the write buffer is drained, evcom_socket_close will shutdown the
* writing end of the socket and will close the read end once the server
* replies with an EOF.
*/
void evnet_socket_close (evnet_socket *);
void evcom_socket_close (evcom_socket *);

/* Do not wait for the server to reply with EOF. This will only be called
* once the write buffer is drained.
* Warning: For TCP socket, the OS kernel may (should) reply with RST
* packets if this is called when data is still being received from the
* server.
*/
void evnet_socket_full_close (evnet_socket *);
void evcom_socket_full_close (evcom_socket *);

/* The most extreme measure.
* Will not wait for the write queue to complete.
*/
void evnet_socket_force_close (evnet_socket *);
void evcom_socket_force_close (evcom_socket *);


#if EVNET_HAVE_GNUTLS
/* Tells the socket to use transport layer security (SSL). evnet_socket does
#if EVCOM_HAVE_GNUTLS
/* Tells the socket to use transport layer security (SSL). evcom_socket does
* not want to make any decisions about security requirements, so the
* majoirty of GnuTLS configuration is left to the user. Only the transport
* layer of GnuTLS is controlled by evnet_socket. That is, do not use
* layer of GnuTLS is controlled by evcom_socket. That is, do not use
* gnutls_transport_* functions. Do use the rest of GnuTLS's API.
*/
void evnet_socket_set_secure_session (evnet_socket *, gnutls_session_t);
void evcom_socket_set_secure_session (evcom_socket *, gnutls_session_t);
#endif

evnet_buf * evnet_buf_new (const char* base, size_t len);
evnet_buf * evnet_buf_new2 (size_t len);
void evnet_buf_destroy (evnet_buf *);
evcom_buf * evcom_buf_new (const char* base, size_t len);
evcom_buf * evcom_buf_new2 (size_t len);
void evcom_buf_destroy (evcom_buf *);


struct evnet_queue {
evnet_queue *prev;
evnet_queue *next;
struct evcom_queue {
evcom_queue *prev;
evcom_queue *next;
};

struct evnet_buf {
struct evcom_buf {
/* public */
char *base;
size_t len;
void (*release) (evnet_buf *); /* called when oi is done with the object */
void (*release) (evcom_buf *); /* called when oi is done with the object */
void *data;

/* private */
size_t written;
evnet_queue queue;
evcom_queue queue;
};

struct evnet_server {
struct evcom_server {
/* read only */
int fd;
#if EV_MULTIPLICITY
Expand All @@ -137,26 +137,26 @@ struct evnet_server {

/* PUBLIC */

evnet_socket* (*on_connection) (evnet_server *, struct sockaddr *remote_addr);
evcom_socket* (*on_connection) (evcom_server *, struct sockaddr *remote_addr);

/* Executed when a server is closed.
* If evnet_server_close() was called errorno will be 0.
* If evcom_server_close() was called errorno will be 0.
* An libev error is indicated with errorno == 1
* Otherwise errorno is a stdlib errno from a system call, e.g. accept()
*/
void (*on_close) (evnet_server *, int errorno);
void (*on_close) (evcom_server *, int errorno);

void *data;
};

struct evnet_socket {
struct evcom_socket {
/* read only */
int fd;
#if EV_MULTIPLICITY
struct ev_loop *loop;
#endif
evnet_server *server;
evnet_queue out_stream;
evcom_server *server;
evcom_queue out_stream;
size_t written;
unsigned attached:1;
unsigned connected:1;
Expand All @@ -165,42 +165,42 @@ struct evnet_socket {
unsigned got_half_close:1;

/* NULL = that end of the socket is closed. */
int (*read_action) (evnet_socket *);
int (*write_action) (evnet_socket *);
int (*read_action) (evcom_socket *);
int (*write_action) (evcom_socket *);

/* ERROR CODES. 0 = no error. Check on_close. */
int errorno;
#if EVNET_HAVE_GNUTLS
#if EVCOM_HAVE_GNUTLS
int gnutls_errorno;
#endif

/* private */
ev_io write_watcher;
ev_io read_watcher;
ev_timer timeout_watcher;
#if EVNET_HAVE_GNUTLS
#if EVCOM_HAVE_GNUTLS
gnutls_session_t session;
#endif

/* public */
size_t chunksize; /* the maximum chunk that on_read() will return */
void (*on_connect) (evnet_socket *);
void (*on_read) (evnet_socket *, const void *buf, size_t count);
void (*on_drain) (evnet_socket *);
void (*on_close) (evnet_socket *);
void (*on_timeout) (evnet_socket *);
void (*on_connect) (evcom_socket *);
void (*on_read) (evcom_socket *, const void *buf, size_t count);
void (*on_drain) (evcom_socket *);
void (*on_close) (evcom_socket *);
void (*on_timeout) (evcom_socket *);
void *data;
};

EV_INLINE void
evnet_queue_init (evnet_queue *q)
evcom_queue_init (evcom_queue *q)
{
q->prev = q;
q->next = q;
}

EV_INLINE void
evnet_queue_insert_head (evnet_queue *h, evnet_queue *x)
evcom_queue_insert_head (evcom_queue *h, evcom_queue *x)
{
(x)->next = (h)->next;
(x)->next->prev = x;
Expand All @@ -209,7 +209,7 @@ evnet_queue_insert_head (evnet_queue *h, evnet_queue *x)
}

EV_INLINE void
evnet_queue_remove (evnet_queue *x)
evcom_queue_remove (evcom_queue *x)
{
(x)->next->prev = (x)->prev;
(x)->prev->next = (x)->next;
Expand All @@ -219,14 +219,14 @@ evnet_queue_remove (evnet_queue *x)
#endif
}

#define evnet_queue_empty(h) (h == (h)->prev)
#define evnet_queue_head(h) (h)->next
#define evnet_queue_last(h) (h)->prev
#define evnet_queue_data(q, type, link) \
#define evcom_queue_empty(h) (h == (h)->prev)
#define evcom_queue_head(h) (h)->next
#define evcom_queue_last(h) (h)->prev
#define evcom_queue_data(q, type, link) \
(type *) ((unsigned char *) q - offsetof(type, link))


#ifdef __cplusplus
}
#endif
#endif /* evnet_h */
#endif /* evcom_h */
30 changes: 15 additions & 15 deletions deps/evnet/test/echo.c → deps/evcom/test/echo.c
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@


#include <ev.h>
#include <evnet.h>
#include <evcom.h>
#include <gnutls/gnutls.h>

#define HOST "127.0.0.1"
Expand All @@ -21,15 +21,15 @@
static int nconnections;

static void
on_peer_close (evnet_socket *socket)
on_peer_close (evcom_socket *socket)
{
assert(socket->errorno == 0);
//printf("server connection closed\n");
free(socket);
}

static void
on_peer_timeout (evnet_socket *socket)
on_peer_timeout (evcom_socket *socket)
{
assert(socket);
fprintf(stderr, "peer connection timeout\n");
Expand All @@ -42,21 +42,21 @@ on_peer_timeout (evnet_socket *socket)
#define TIMEOUT 5.0

static void
on_peer_read (evnet_socket *socket, const void *base, size_t len)
on_peer_read (evcom_socket *socket, const void *base, size_t len)
{
if(len == 0) return;

evnet_socket_write_simple(socket, base, len);
evcom_socket_write_simple(socket, base, len);
}

static evnet_socket*
on_server_connection (evnet_server *server, struct sockaddr *addr)
static evcom_socket*
on_server_connection (evcom_server *server, struct sockaddr *addr)
{
assert(server);
assert(addr);

evnet_socket *socket = malloc(sizeof(evnet_socket));
evnet_socket_init(socket, TIMEOUT);
evcom_socket *socket = malloc(sizeof(evcom_socket));
evcom_socket_init(socket, TIMEOUT);
socket->on_read = on_peer_read;
socket->on_close = on_peer_close;
socket->on_timeout = on_peer_timeout;
Expand All @@ -73,12 +73,12 @@ int
main (void)
{
int r;
evnet_server server;
evcom_server server;

//printf("sizeof(evnet_server): %d\n", sizeof(evnet_server));
//printf("sizeof(evnet_socket): %d\n", sizeof(evnet_socket));
//printf("sizeof(evcom_server): %d\n", sizeof(evcom_server));
//printf("sizeof(evcom_socket): %d\n", sizeof(evcom_socket));

evnet_server_init(&server);
evcom_server_init(&server);
server.on_connection = on_server_connection;

struct addrinfo *servinfo;
Expand All @@ -90,9 +90,9 @@ main (void)
r = getaddrinfo(NULL, PORT, &hints, &servinfo);
assert(r == 0);

r = evnet_server_listen(&server, servinfo, 10);
r = evcom_server_listen(&server, servinfo, 10);
assert(r == 0);
evnet_server_attach(EV_DEFAULT_ &server);
evcom_server_attach(EV_DEFAULT_ &server);

ev_loop(EV_DEFAULT_ 0);

Expand Down
Loading

0 comments on commit 0fb0af3

Please sign in to comment.