bottleneck testcase based on rubbos
[bottlenecks.git] / rubbos / app / httpd-2.0.64 / srclib / apr / network_io / os2 / sendrecv_udp.c
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_arch_networkio.h"
18 #include "apr_errno.h"
19 #include "apr_general.h"
20 #include "apr_network_io.h"
21 #include "apr_support.h"
22 #include "apr_lib.h"
23 #include <sys/time.h>
24
25
26 APR_DECLARE(apr_status_t) apr_socket_sendto(apr_socket_t *sock, 
27                                             apr_sockaddr_t *where,
28                                             apr_int32_t flags, const char *buf,
29                                             apr_size_t *len)
30 {
31     apr_ssize_t rv;
32     int serrno;
33
34     do {
35         rv = sendto(sock->socketdes, buf, (*len), flags, 
36                     (struct sockaddr*)&where->sa,
37                     where->salen);
38     } while (rv == -1 && (serrno = sock_errno()) == EINTR);
39
40     if (rv == -1 && serrno == SOCEWOULDBLOCK && sock->timeout != 0) {
41         apr_status_t arv = apr_wait_for_io_or_timeout(NULL, sock, 0);
42
43         if (arv != APR_SUCCESS) {
44             *len = 0;
45             return arv;
46         } else {
47             do {
48                 rv = sendto(sock->socketdes, buf, *len, flags,
49                             (const struct sockaddr*)&where->sa,
50                             where->salen);
51             } while (rv == -1 && (serrno = sock_errno()) == SOCEINTR);
52         }
53     }
54
55     if (rv == -1) {
56         *len = 0;
57         return APR_FROM_OS_ERROR(serrno);
58     }
59
60     *len = rv;
61     return APR_SUCCESS;
62 }
63
64
65
66 APR_DECLARE(apr_status_t) apr_socket_recvfrom(apr_sockaddr_t *from,
67                                               apr_socket_t *sock,
68                                               apr_int32_t flags, char *buf,
69                                               apr_size_t *len)
70 {
71     apr_ssize_t rv;
72     int serrno;
73
74     do {
75         rv = recvfrom(sock->socketdes, buf, (*len), flags, 
76                       (struct sockaddr*)&from->sa, &from->salen);
77     } while (rv == -1 && (serrno = sock_errno()) == EINTR);
78
79     if (rv == -1 && serrno == SOCEWOULDBLOCK && sock->timeout != 0) {
80         apr_status_t arv = apr_wait_for_io_or_timeout(NULL, sock, 1);
81
82         if (arv != APR_SUCCESS) {
83             *len = 0;
84             return arv;
85         } else {
86             do {
87                 rv = recvfrom(sock->socketdes, buf, *len, flags,
88                               (struct sockaddr*)&from->sa, &from->salen);
89                 } while (rv == -1 && (serrno = sock_errno()) == EINTR);
90         }
91     }
92
93     if (rv == -1) {
94         (*len) = 0;
95         return APR_FROM_OS_ERROR(serrno);
96     }
97
98     (*len) = rv;
99
100     if (rv == 0 && sock->type == SOCK_STREAM)
101         return APR_EOF;
102
103     return APR_SUCCESS;
104 }
105
106 /* deprecated */
107 APR_DECLARE(apr_status_t) apr_sendto(apr_socket_t *sock, apr_sockaddr_t *where,
108                                      apr_int32_t flags, const char *buf,
109                                      apr_size_t *len)
110 {
111     return apr_socket_sendto(sock, where, flags, buf, len);
112 }
113
114
115
116 APR_DECLARE(apr_status_t) apr_recvfrom(apr_sockaddr_t *from,
117                                        apr_socket_t *sock,
118                                        apr_int32_t flags, char *buf,
119                                        apr_size_t *len)
120 {
121     return apr_socket_recvfrom(from, sock, flags, buf, len);
122 }