Esempio n. 1
0
uint Socket::send(const byte* buf, unsigned int sz, unsigned int& written)
{
    const byte* pos = buf;
    const byte* end = pos + sz;

    wouldBlock_ = false;

    /* Remove send()/recv() hooks once non-blocking send is implemented. */
    while (pos != end) {
        int sent = send_func_(ptr_, pos, static_cast<int>(end - pos));
        if (sent == -1) {
            if (get_lastError() == SOCKET_EWOULDBLOCK || 
                get_lastError() == SOCKET_EAGAIN) {
                wouldBlock_  = true; // would have blocked this time only
                nonBlocking_ = true; // nonblocking, win32 only way to tell 
                return 0;
            }
            return static_cast<uint>(-1);
        }
        pos += sent;
        written += sent;
    }

    return sz;
}
uint Socket::send(const byte* buf, unsigned int sz) const
{
    const byte* pos = buf;
    const byte* end = pos + sz;

    /* Remove send()/recv() hooks once non-blocking send is implemented. */
    while (pos != end) {
        int sent = send_func_(ptr_, pos, static_cast<int>(end - pos));

    if (sent == -1)
        return 0;

        pos += sent;
    }

    return sz;
}