~ubuntu-branches/ubuntu/feisty/apache2/feisty

« back to all changes in this revision

Viewing changes to srclib/apr/network_io/os2/sendrecv_udp.c

  • Committer: Bazaar Package Importer
  • Author(s): Andreas Barth
  • Date: 2006-12-09 21:05:45 UTC
  • mfrom: (0.6.1 upstream)
  • Revision ID: james.westby@ubuntu.com-20061209210545-h70s0xaqc2v8vqr2
Tags: 2.2.3-3.2
* Non-maintainer upload.
* 043_ajp_connection_reuse: Patch from upstream Bugzilla, fixing a critical
  issue with regard to connection reuse in mod_proxy_ajp.
  Closes: #396265

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/* Copyright 2000-2005 The Apache Software Foundation or its licensors, as
 
2
 * applicable.
 
3
 *
 
4
 * Licensed under the Apache License, Version 2.0 (the "License");
 
5
 * you may not use this file except in compliance with the License.
 
6
 * 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
}