Improve string search
[MonkeyD.git] / src / conn_switch.c
blob8e3b00a8037245ca333092696ab8178f31e0848e
1 /* Monkey HTTP Daemon
2 * ------------------
3 * Copyright (C) 2008, Eduardo Silva P.
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU Library General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
20 #include "monkey.h"
21 #include "http.h"
22 #include "conn_switch.h"
23 #include <string.h>
24 #include <stdio.h>
26 int mk_conn_switch_read(int socket)
28 int ret;
30 ret = mk_handler_read(socket);
31 return ret;
34 int mk_conn_switch_write(int socket)
36 int ret=-1, ka, efd;
37 struct client_request *cr;
39 /* Get node from schedule list node which contains
40 * the information regarding to the current client/socket
42 cr = mk_get_client_request_from_fd(socket);
44 if(!cr)
46 return -1;
49 ret = mk_handler_write(socket, cr);
50 ka = mk_http_keepalive_check(socket, cr);
52 /* if ret < 0, means that some error
53 * happened in the writer call, in the
54 * other hand, 0 means a successful request
55 * processed, if ret > 0 means that some data
56 * still need to be send.
59 if(ret <= 0)
61 free_list_requests(cr);
63 /* We need to ask to http_keepalive if this
64 * connection can continue working or we must
65 * close it.
68 if(ka<0)
70 mk_remove_client_request(socket);
71 return -1;
73 else{
74 memset(cr->body, '\0', sizeof(cr->body));
75 cr->body_length = 0;
76 cr->counter_connections++;
77 efd = mk_sched_get_thread_poll();
78 mk_epoll_socket_change_mode(efd, socket, MK_EPOLL_READ);
79 return 0;
82 else if(ret > 0)
84 return 0;
87 /* avoid to make gcc cry :_( */
88 return -1;
91 int mk_conn_switch(int action, int socket)
93 int status=-1;
95 switch(action)
97 case MK_CONN_SWITCH_READ:
98 status = mk_conn_switch_read(socket);
99 break;
100 case MK_CONN_SWITCH_WRITE:
101 status = mk_conn_switch_write(socket);
102 break;
105 return status;