View | Details | Raw Unified | Return to bug 43309
Collapse All | Expand All

(-)sendrecv.c (+68 lines)
Lines 93-99 Link Here
93
    return dwBytes == 0 ? APR_EOF : APR_SUCCESS;
93
    return dwBytes == 0 ? APR_EOF : APR_SUCCESS;
94
}
94
}
95
95
96
APR_DECLARE(apr_status_t) apr_socket_sendtov(apr_socket_t *sock, 
97
                                             apr_sockaddr_t *where,
98
                                             apr_int32_t flags,
99
                                             const struct iovec *vec,
100
                                             apr_int32_t in_vec,
101
                                             apr_size_t *nbytes)
102
{
96
103
104
    apr_status_t rc = APR_SUCCESS;
105
    apr_ssize_t rv;
106
    apr_size_t cur_len;
107
    apr_int32_t nvec = 0;
108
    int i, j = 0;
109
    DWORD dwBytes = 0;
110
    WSABUF *pWsaBuf;
111
112
    for (i = 0; i < in_vec; i++) {
113
        cur_len = vec[i].iov_len;
114
        nvec++;
115
        while (cur_len > APR_DWORD_MAX) {
116
            nvec++;
117
            cur_len -= APR_DWORD_MAX;
118
        } 
119
    }
120
121
    pWsaBuf = (nvec <= WSABUF_ON_STACK) ? _alloca(sizeof(WSABUF) * (nvec))
122
                                         : malloc(sizeof(WSABUF) * (nvec));
123
    if (!pWsaBuf)
124
        return APR_ENOMEM;
125
126
    for (i = 0; i < in_vec; i++) {
127
        char * base = vec[i].iov_base;
128
        cur_len = vec[i].iov_len;
129
        
130
        do {
131
            if (cur_len > APR_DWORD_MAX) {
132
                pWsaBuf[j].buf = base;
133
                pWsaBuf[j].len = APR_DWORD_MAX;
134
                cur_len -= APR_DWORD_MAX;
135
                base += APR_DWORD_MAX;
136
            }
137
            else {
138
                pWsaBuf[j].buf = base;
139
                pWsaBuf[j].len = (DWORD)cur_len;
140
                cur_len = 0;
141
            }
142
            j++;
143
144
        } while (cur_len > 0);
145
    }
146
147
    for (i = 0; i < nvec; i++) {
148
        rv = sendto(sock->socketdes, pWsaBuf[i].buf, pWsaBuf[i].len, flags,
149
                    (const struct sockaddr*)&where->sa, 
150
                    where->salen);
151
        if (rv == SOCKET_ERROR) {
152
            rc = apr_get_netos_error();
153
            break;
154
        }
155
        dwBytes += rv;
156
    }
157
158
    if (nvec > WSABUF_ON_STACK) 
159
        free(pWsaBuf);
160
161
    *nbytes = dwBytes;
162
    return rc;
163
}
164
97
APR_DECLARE(apr_status_t) apr_socket_sendv(apr_socket_t *sock,
165
APR_DECLARE(apr_status_t) apr_socket_sendv(apr_socket_t *sock,
98
                                           const struct iovec *vec,
166
                                           const struct iovec *vec,
99
                                           apr_int32_t in_vec, apr_size_t *nbytes)
167
                                           apr_int32_t in_vec, apr_size_t *nbytes)

Return to bug 43309