diff options
author | LAN-TW <lantw44@gmail.com> | 2014-01-14 16:47:54 +0800 |
---|---|---|
committer | LAN-TW <lantw44@gmail.com> | 2014-01-14 16:47:54 +0800 |
commit | 08b63dcd438ee4ec68fe9eb61b6cd42ee6684963 (patch) | |
tree | 4f3704448c7330f0a8c383e6193af6e5a40ad2cb /hw4/chttpd/chttpd-conn.c | |
parent | d24aa7d6ceac4914906ce76aa729fd5c7011eb3d (diff) | |
download | sp2013-08b63dcd438ee4ec68fe9eb61b6cd42ee6684963.tar.gz sp2013-08b63dcd438ee4ec68fe9eb61b6cd42ee6684963.tar.zst sp2013-08b63dcd438ee4ec68fe9eb61b6cd42ee6684963.zip |
HW4: 準備處理 connection
Diffstat (limited to 'hw4/chttpd/chttpd-conn.c')
-rw-r--r-- | hw4/chttpd/chttpd-conn.c | 60 |
1 files changed, 60 insertions, 0 deletions
diff --git a/hw4/chttpd/chttpd-conn.c b/hw4/chttpd/chttpd-conn.c new file mode 100644 index 0000000..494742d --- /dev/null +++ b/hw4/chttpd/chttpd-conn.c @@ -0,0 +1,60 @@ +/* b01902062 藍挺瑋 */ +#ifdef HAVE_CONFIG_H +# include "config.h" +#endif + +#include "chttpd-conn.h" +#include "chttpd-log.h" +#include "chttpd-server.h" +#include <l4list.h> + +#include <stdlib.h> +#include <unistd.h> + +#define CHTTPD_CONN_THREAD_INIT \ + ChttpdConn* conn = ptr_to_ChttpdConn; \ + ChttpdServer* server = conn->server; \ + ChttpdLog* hlog = conn->hlog + +#define CHTTPD_CONN_THREAD_DESTROY \ + chttpd_log_write (hlog, "[%4llu] terminated", conn->id); \ + pthread_rwlock_wrlock (&server->lock); \ + lbs_list_remove (server->conn, conn->conn_node); \ + pthread_rwlock_unlock (&server->lock); \ + return NULL + + +void* chttpd_conn_admin (void* ptr_to_ChttpdConn) { + CHTTPD_CONN_THREAD_INIT; + + CHTTPD_CONN_THREAD_DESTROY; +} + +void* chttpd_conn_http (void* ptr_to_ChttpdConn) { + CHTTPD_CONN_THREAD_INIT; + + CHTTPD_CONN_THREAD_DESTROY; +} + +void chttpd_conn_ctor (void* conn_generic, unsigned long long id, int connfd, + ChttpdLog* hlog, ChttpdServer* server, LbsListMeta* slist) { + + ChttpdConn* conn = conn_generic; + conn->id = id; + conn->connfd = connfd; + conn->hlog = chttpd_log_ref (hlog); + conn->server = server; + conn->slist = slist; + pthread_rwlock_init (&conn->lock, NULL); + conn->pid = -1; +} + +void chttpd_conn_dtor (void* conn_generic) { + ChttpdConn* conn = conn_generic; + close (conn->connfd); + chttpd_log_unref (conn->hlog); + pthread_rwlock_wrlock (&conn->lock); + pthread_rwlock_unlock (&conn->lock); + pthread_rwlock_destroy (&conn->lock); + free (conn); +} |