"Fossies" - the Fresh Open Source Software Archive

Member "wrk-4.2.0/src/net.c" (7 Feb 2021, 824 Bytes) of package /linux/www/wrk-4.2.0.tar.gz:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) C and C++ source code syntax highlighting (style: standard) with prefixed line numbers and code folding option. Alternatively you can here view or download the uninterpreted source code file. For more information about "net.c" see the Fossies "Dox" file reference documentation.

    1 // Copyright (C) 2013 - Will Glozer.  All rights reserved.
    2 
    3 #include <errno.h>
    4 #include <unistd.h>
    5 #include <sys/ioctl.h>
    6 
    7 #include "net.h"
    8 
    9 status sock_connect(connection *c, char *host) {
   10     return OK;
   11 }
   12 
   13 status sock_close(connection *c) {
   14     return OK;
   15 }
   16 
   17 status sock_read(connection *c, size_t *n) {
   18     ssize_t r = read(c->fd, c->buf, sizeof(c->buf));
   19     *n = (size_t) r;
   20     return r >= 0 ? OK : ERROR;
   21 }
   22 
   23 status sock_write(connection *c, char *buf, size_t len, size_t *n) {
   24     ssize_t r;
   25     if ((r = write(c->fd, buf, len)) == -1) {
   26         switch (errno) {
   27             case EAGAIN: return RETRY;
   28             default:     return ERROR;
   29         }
   30     }
   31     *n = (size_t) r;
   32     return OK;
   33 }
   34 
   35 size_t sock_readable(connection *c) {
   36     int n, rc;
   37     rc = ioctl(c->fd, FIONREAD, &n);
   38     return rc == -1 ? 0 : n;
   39 }