Skip to content

SocketSend

Description

Blocking write to a connected socket. Does not partial-retry; the caller decides whether to loop on short writes.

Parameters

Name Direction Description
self in Socket to write to.
buf in Source buffer.
n in Number of bytes to send.

Success

returns number of bytes sent.

Failure

returns -1; logs the failing syscall.

Usage example (Cross-references)

Usage examples (Cross-references)
        const char *payload = "hello from socket test";
        size        n       = (size)ZstrLen(payload);
        if (SocketSend(&client, payload, n) != (i64)n) {
            SocketClose(&server);
            SocketClose(&client);
    }
    
    i64 SocketSend(Socket *self, const void *buf, size n) {
        if (!self || !buf) {
            LOG_ERROR("SocketSend: NULL argument");
    i64 SocketSend(Socket *self, const void *buf, size n) {
        if (!self || !buf) {
            LOG_ERROR("SocketSend: NULL argument");
            return -1;
        }
        ssize_t ret = send(self->fd, buf, (size_t)n, MSG_NOSIGNAL);
        if (ret < 0) {
            LOG_SYS_ERROR("SocketSend: send() failed");
            return -1;
        }
    static void proxy_pump(Socket *a, Socket *b, const char *first_chunk, size first_len) {
        if (first_chunk && first_len > 0) {
            if (SocketSend(b, first_chunk, first_len) < 0) {
                return;
            }
                    return;
                }
                if (SocketSend(b, buf, (size)n) < 0) {
                    return;
                }
                    return;
                }
                if (SocketSend(a, buf, (size)n) < 0) {
                    return;
                }
Last updated on