Apache HTTPD
apr_buckets_socket.c
Go to the documentation of this file.
1/* Licensed to the Apache Software Foundation (ASF) under one or more
2 * contributor license agreements. See the NOTICE file distributed with
3 * this work for additional information regarding copyright ownership.
4 * The ASF licenses this file to You under the Apache License, Version 2.0
5 * (the "License"); you may not use this file except in compliance with
6 * the License. You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17#include "apr_buckets.h"
18
21{
22 apr_socket_t *p = a->data;
23 char *buf;
24 apr_status_t rv;
26
27 if (block == APR_NONBLOCK_READ) {
30 }
31
32 *str = NULL;
34 buf = apr_bucket_alloc(*len, a->list); /* XXX: check for failure? */
35
36 rv = apr_socket_recv(p, buf, len);
37
38 if (block == APR_NONBLOCK_READ) {
40 }
41
42 if (rv != APR_SUCCESS && rv != APR_EOF) {
44 return rv;
45 }
46 /*
47 * If there's more to read we have to keep the rest of the socket
48 * for later. XXX: Note that more complicated bucket types that
49 * refer to data not in memory and must therefore have a read()
50 * function similar to this one should be wary of copying this
51 * code because if they have a destroy function they probably
52 * want to migrate the bucket's subordinate structure from the
53 * old bucket to a raw new one and adjust it as appropriate,
54 * rather than destroying the old one and creating a completely
55 * new bucket.
56 *
57 * Even if there is nothing more to read, don't close the socket here
58 * as we have to use it to send any response :) We could shut it
59 * down for reading, but there is no benefit to doing so.
60 */
61 if (*len > 0) {
63 /* Change the current bucket to refer to what we read */
65 h = a->data;
66 h->alloc_len = APR_BUCKET_BUFF_SIZE; /* note the real buffer size */
67 *str = buf;
69 }
70 else {
73 *str = a->data;
74 }
75 return APR_SUCCESS;
76}
77
79{
80 /*
81 * XXX: We rely on a cleanup on some pool or other to actually
82 * destroy the socket. We should probably explicitly call apr to
83 * destroy it instead.
84 *
85 * Note that typically the socket is allocated from the connection pool
86 * so it will disappear when the connection is finished.
87 */
89 b->length = (apr_size_t)(-1);
90 b->start = -1;
91 b->data = p;
92
93 return b;
94}
95
98{
99 apr_bucket *b = apr_bucket_alloc(sizeof(*b), list);
100
102 b->free = apr_bucket_free;
103 b->list = list;
104 return apr_bucket_socket_make(b, p);
105}
106
const char apr_size_t len
Definition ap_regex.h:187
APR-UTIL Buckets/Bucket Brigades.
static apr_status_t socket_bucket_read(apr_bucket *a, const char **str, apr_size_t *len, apr_read_type_e block)
APU_DECLARE(void)
Computes SipHash-2-4, producing a 64bit (APR_SIPHASH_DSIZE) hash from a message and a 128bit (APR_SIP...
Definition apr_sha1.c:206
const unsigned char * buf
Definition util_md5.h:50
#define APR_EOF
Definition apr_errno.h:461
#define APR_BUCKET_INIT(e)
APU_DECLARE_DATA const apr_bucket_type_t apr_bucket_type_socket
#define APR_BUCKET_INSERT_AFTER(a, b)
apr_read_type_e
Definition apr_buckets.h:57
#define APR_BUCKET_BUFF_SIZE
Definition apr_buckets.h:54
apr_bucket apr_bucket_brigade * a
@ APR_NONBLOCK_READ
Definition apr_buckets.h:59
apr_size_t size
const apr_array_header_t * list
Definition apr_cstr.h:105
#define APR_SUCCESS
Definition apr_errno.h:225
int apr_status_t
Definition apr_errno.h:44
const apr_hash_t * h
Definition apr_hash.h:97
apr_pool_t * b
Definition apr_pools.h:529
apr_int64_t apr_interval_time_t
Definition apr_time.h:55
apr_pool_t * p
Definition md_event.c:32
return NULL
Definition mod_so.c:359
apr_bucket_alloc_t * list
void * data
apr_status_t apr_socket_recv(apr_socket_t *sock, char *buf, apr_size_t *len)
Definition sendrecv.c:70
apr_status_t apr_socket_timeout_set(apr_socket_t *sock, apr_interval_time_t t)
Definition sockopt.c:75
apr_status_t apr_socket_timeout_get(apr_socket_t *sock, apr_interval_time_t *t)
Definition sockopt.c:355
#define str
IN ULONG IN INT timeout