Skip to content
This repository
Browse code

WIP: new conn 2

  • Loading branch information...
commit 216073a604d3e0a84ae6e1e9b2f5136bc2f3f042 1 parent 390c8b3
Alvaro Lopez Ortega authored January 12, 2012
94  cherokee/connection.c
... ...
@@ -0,0 +1,94 @@
  1
+/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
  2
+
  3
+/* Cherokee
  4
+ *
  5
+ * Authors:
  6
+ *      Alvaro Lopez Ortega <alvaro@alobbs.com>
  7
+ *
  8
+ * Copyright (C) 2001-2011 Alvaro Lopez Ortega
  9
+ *
  10
+ * This program is free software; you can redistribute it and/or
  11
+ * modify it under the terms of version 2 of the GNU General Public
  12
+ * License as published by the Free Software Foundation.
  13
+ *
  14
+ * This program is distributed in the hope that it will be useful,
  15
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
  16
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  17
+ * GNU General Public License for more details.
  18
+ *
  19
+ * You should have received a copy of the GNU General Public License
  20
+ * along with this program; if not, write to the Free Software
  21
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
  22
+ * 02110-1301, USA.
  23
+ */
  24
+
  25
+#include "common-internal.h"
  26
+#include "connection.h"
  27
+
  28
+
  29
+ret_t
  30
+cherokee_connection_init (cherokee_connection_t *conn)
  31
+{
  32
+	conn->keepalive = 0;
  33
+
  34
+	cherokee_socket_init (&conn->socket);
  35
+	cherokee_connection_poll_init (&conn->polling_aim);
  36
+
  37
+	INIT_LIST_HEAD (&conn->requests);
  38
+	return ret_ok;
  39
+}
  40
+
  41
+
  42
+static void
  43
+reuse_requests (cherokee_connection_t *conn)
  44
+{
  45
+	cherokee_thread_t *thd      = CONN_THREAD(conn);
  46
+	cherokee_list_t   *i, *tmp;
  47
+
  48
+	list_for_each_safe (i, tmp, &conn->requests) {
  49
+		if (thd != NULL) {
  50
+			cherokee_thread_recycle_request (thd, REQ(i));
  51
+		} else {
  52
+			cherokee_request_free (REQ(i));
  53
+		}
  54
+	}
  55
+}
  56
+
  57
+
  58
+ret_t
  59
+cherokee_connection_mrproper (cherokee_connection_t *conn)
  60
+{
  61
+	/* Polling aim */
  62
+	if (conn->polling_aim.fd != -1) {
  63
+                cherokee_fd_close (conn->polling_aim.fd);
  64
+	}
  65
+
  66
+	cherokee_connection_poll_mrproper (&conn->polling_aim);
  67
+
  68
+	/* Connection socket */
  69
+	cherokee_socket_mrproper (&conn->socket);
  70
+
  71
+	/* Free requests */
  72
+	reuse_requests (conn);
  73
+
  74
+	return ret_ok;
  75
+}
  76
+
  77
+
  78
+ret_t
  79
+cherokee_connection_clean (cherokee_connection_t *conn)
  80
+{
  81
+	cherokee_list_t *i, *tmp;
  82
+
  83
+	/* Polling aim */
  84
+	if (conn->polling_aim.fd != -1) {
  85
+                cherokee_fd_close (conn->polling_aim.fd);
  86
+	}
  87
+
  88
+	cherokee_connection_poll_clean (&conn->polling_aim);
  89
+
  90
+	/* Free requests */
  91
+	reuse_requests (conn);
  92
+
  93
+	return ret_ok;
  94
+}
54  cherokee/connection.h
... ...
@@ -0,0 +1,54 @@
  1
+/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
  2
+
  3
+/* Cherokee
  4
+ *
  5
+ * Authors:
  6
+ *      Alvaro Lopez Ortega <alvaro@alobbs.com>
  7
+ *
  8
+ * Copyright (C) 2001-2011 Alvaro Lopez Ortega
  9
+ *
  10
+ * This program is free software; you can redistribute it and/or
  11
+ * modify it under the terms of version 2 of the GNU General Public
  12
+ * License as published by the Free Software Foundation.
  13
+ *
  14
+ * This program is distributed in the hope that it will be useful,
  15
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
  16
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  17
+ * GNU General Public License for more details.
  18
+ *
  19
+ * You should have received a copy of the GNU General Public License
  20
+ * along with this program; if not, write to the Free Software
  21
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
  22
+ * 02110-1301, USA.
  23
+ */
  24
+
  25
+#ifndef CHEROKEE_REQUEST_H
  26
+#define CHEROKEE_REQUEST_H
  27
+
  28
+#include "common.h"
  29
+#include "buffer.h"
  30
+#include "socket.h"
  31
+#include "list.h"
  32
+#include "connection-poll.h"
  33
+
  34
+CHEROKEE_BEGIN_DECLS
  35
+
  36
+typedef struct {
  37
+	cherokee_socket_t          socket;
  38
+	uint32_t                   keepalive;
  39
+	cherokee_connection_pool_t polling_aim;
  40
+	cherokee_list_t            requests;
  41
+} cherokee_connection_t;
  42
+
  43
+#define CONN(c) ((cherokee_connection_t *)(c))
  44
+
  45
+
  46
+/* Public methods
  47
+ */
  48
+ret_t cherokee_connection_init     (cherokee_connection_t *conn);
  49
+ret_t cherokee_connection_mrproper (cherokee_connection_t *conn);
  50
+
  51
+
  52
+CHEROKEE_END_DECLS
  53
+
  54
+#endif /* CHEROKEE_REQUEST_H */

0 notes on commit 216073a

Please sign in to comment.
Something went wrong with that request. Please try again.