1
/* Copyright 2002-2004 Justin Erenkrantz and Greg Stein
3
* Licensed under the Apache License, Version 2.0 (the "License");
4
* you may not use this file except in compliance with the License.
5
* You may obtain a copy of the License at
7
* http://www.apache.org/licenses/LICENSE-2.0
9
* Unless required by applicable law or agreed to in writing, software
10
* distributed under the License is distributed on an "AS IS" BASIS,
11
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
* See the License for the specific language governing permissions and
13
* limitations under the License.
16
#include <apr_pools.h>
18
#include <apr_version.h>
21
#include "serf_bucket_util.h"
23
#include "serf_private.h"
25
static apr_status_t read_from_client(serf_incoming_t *client)
30
static apr_status_t write_to_client(serf_incoming_t *client)
35
apr_status_t serf__process_client(serf_incoming_t *client, apr_int16_t events)
38
if ((events & APR_POLLIN) != 0) {
39
rv = read_from_client(client);
45
if ((events & APR_POLLHUP) != 0) {
46
return APR_ECONNRESET;
49
if ((events & APR_POLLERR) != 0) {
53
if ((events & APR_POLLOUT) != 0) {
54
rv = write_to_client(client);
63
apr_status_t serf__process_listener(serf_listener_t *l)
68
/* THIS IS NOT OPTIMAL */
69
apr_pool_create(&p, l->pool);
71
rv = apr_socket_accept(&in, l->skt, p);
78
rv = l->accept(l->ctx, l, l->accept_baton, in, p);
89
apr_status_t serf_incoming_create(
90
serf_incoming_t **client,
94
serf_incoming_request_cb_t request,
98
serf_incoming_t *ic = apr_palloc(pool, sizeof(*ic));
101
ic->baton.type = SERF_IO_CLIENT;
102
ic->baton.u.client = ic;
103
ic->request_baton = request_baton;
104
ic->request = request;
106
ic->desc.desc_type = APR_POLL_SOCKET;
107
ic->desc.desc.s = ic->skt;
108
ic->desc.reqevents = APR_POLLIN;
110
rv = ctx->pollset_add(ctx->pollset_baton,
111
&ic->desc, &ic->baton);
118
apr_status_t serf_listener_create(
119
serf_listener_t **listener,
124
serf_accept_client_t accept,
129
serf_listener_t *l = apr_palloc(pool, sizeof(*l));
132
l->baton.type = SERF_IO_LISTENER;
133
l->baton.u.listener = l;
135
l->accept_baton = accept_baton;
137
apr_pool_create(&l->pool, pool);
139
rv = apr_sockaddr_info_get(&sa, host, APR_UNSPEC, port, 0, l->pool);
143
rv = apr_socket_create(&l->skt, sa->family, SOCK_STREAM,
144
APR_PROTO_TCP, l->pool);
148
rv = apr_socket_opt_set(l->skt, APR_SO_REUSEADDR, 1);
152
rv = apr_socket_bind(l->skt, sa);
156
rv = apr_socket_listen(l->skt, 5);
160
l->desc.desc_type = APR_POLL_SOCKET;
161
l->desc.desc.s = l->skt;
162
l->desc.reqevents = APR_POLLIN;
164
rv = ctx->pollset_add(ctx->pollset_baton,
165
&l->desc, &l->baton);