Changeset ee59ede for benchmark/io/http


Ignore:
Timestamp:
Jan 14, 2021, 2:32:18 PM (3 years ago)
Author:
Thierry Delisle <tdelisle@…>
Branches:
ADT, arm-eh, ast-experimental, enum, forall-pointer-decay, jacob/cs343-translation, master, new-ast-unique-expr, pthread-emulation, qualifiedEnum
Children:
153dc387
Parents:
7222630
Message:

Improved error handling in server

Location:
benchmark/io/http
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • benchmark/io/http/protocol.cfa

    r7222630 ree59ede  
    2424        "HTTP/1.1 400 Bad Request\nServer: HttoForall\nDate: %s \nContent-Type: text/plain\nContent-Length: 0 \n\n",
    2525        "HTTP/1.1 404 Not Found\nServer: HttoForall\nDate: %s \nContent-Type: text/plain\nContent-Length: 0 \n\n",
     26        "HTTP/1.1 408 Request Timeout\nServer: HttoForall\nDate: %s \nContent-Type: text/plain\nContent-Length: 0 \n\n",
    2627        "HTTP/1.1 413 Payload Too Large\nServer: HttoForall\nDate: %s \nContent-Type: text/plain\nContent-Length: 0 \n\n",
    2728        "HTTP/1.1 414 URI Too Long\nServer: HttoForall\nDate: %s \nContent-Type: text/plain\nContent-Length: 0 \n\n",
     
    3435        400,
    3536        404,
     37        408,
    3638        413,
    3739        414,
     
    4951                int ret = cfa_write(fd, it, len, 0, -1`s, 0p, 0p);
    5052                // int ret = write(fd, it, len);
    51                 if( ret < 0 ) { if( errno != EAGAIN && errno != EWOULDBLOCK) abort( "'answer error' error: (%d) %s\n", (int)errno, strerror(errno) ); }
     53                if( ret < 0 ) {
     54                        if( errno == ECONNRESET || errno == EPIPE ) return -ECONNRESET;
     55                        if( errno == EAGAIN || errno == EWOULDBLOCK) return -EAGAIN;
     56
     57                        abort( "'answer error' error: (%d) %s\n", (int)errno, strerror(errno) );
     58                }
    5259
    5360                // update it/len
     
    94101                if(ret < 0 ) {
    95102                        if( errno == EAGAIN || errno == EWOULDBLOCK) continue READ;
    96                         // if( errno == EINVAL ) return [E400, true, 0, 0];
     103                        if( errno == ECONNRESET ) return [E408, true, 0, 0];
    97104                        abort( "read error: (%d) %s\n", (int)errno, strerror(errno) );
    98105                }
     
    119126}
    120127
    121 void sendfile( int pipe[2], int fd, int ans_fd, size_t count ) {
     128int sendfile( int pipe[2], int fd, int ans_fd, size_t count ) {
    122129        unsigned sflags = SPLICE_F_MOVE; // | SPLICE_F_MORE;
    123130        off_t offset = 0;
     
    128135                if( ret < 0 ) {
    129136                        if( errno != EAGAIN && errno != EWOULDBLOCK) continue SPLICE1;
     137                        if( errno == ECONNRESET ) return -ECONNRESET;
     138                        if( errno == EPIPE ) return -EPIPE;
    130139                        abort( "splice [0] error: (%d) %s\n", (int)errno, strerror(errno) );
    131140                }
     
    139148                        if( ret < 0 ) {
    140149                                if( errno != EAGAIN && errno != EWOULDBLOCK) continue SPLICE2;
     150                                if( errno == ECONNRESET ) return -ECONNRESET;
     151                                if( errno == EPIPE ) return -EPIPE;
    141152                                abort( "splice [1] error: (%d) %s\n", (int)errno, strerror(errno) );
    142153                        }
     
    145156
    146157        }
     158        return count;
    147159}
    148160
  • benchmark/io/http/protocol.hfa

    r7222630 ree59ede  
    77        E400,
    88        E404,
     9        E408,
    910        E413,
    1011        E414,
     
    2122[HttpCode code, bool closed, * const char file, size_t len] http_read(int fd, []char buffer, size_t len, io_cancellation *);
    2223
    23 void sendfile( int pipe[2], int fd, int ans_fd, size_t count );
     24int sendfile( int pipe[2], int fd, int ans_fd, size_t count );
  • benchmark/io/http/worker.cfa

    r7222630 ree59ede  
    3838                if(fd < 0) {
    3939                        if( errno == ECONNABORTED ) break;
    40                         if( errno == EINVAL && this.done ) break;
     40                        if( this.done && (errno == EINVAL || errno == EBADF) ) break;
    4141                        abort( "accept error: (%d) %s\n", (int)errno, strerror(errno) );
    4242                }
     
    5757
    5858                        // if we are done, break out of the loop
    59                         if( closed ) {
    60                                 if( options.log ) printf("=== Connection closed ===\n");
    61                                 close(fd);
    62                                 continue CONNECTION;
    63                         }
     59                        if( closed ) break REQUEST;
    6460
    6561                        // If this wasn't a request retrun 400
     
    7672
    7773                                // Send the header
    78                                 answer_plain(fd, text, sizeof(text));
     74                                int ret = answer_plain(fd, text, sizeof(text));
     75                                if( ret == -ECONNRESET ) break REQUEST;
    7976
    8077                                if( options.log ) printf("=== Answer sent ===\n");
     
    8683
    8784                                // Send the header
    88                                 answer_empty(fd);
     85                                int ret = answer_empty(fd);
     86                                if( ret == -ECONNRESET ) break REQUEST;
    8987
    9088                                if( options.log ) printf("=== Answer sent ===\n");
     
    107105
    108106                        // Send the header
    109                         answer_header(fd, count);
     107                        int ret = answer_header(fd, count);
     108                        if( ret == -ECONNRESET ) break REQUEST;
    110109
    111110                        // Send the desired file
    112                         sendfile( this.pipe, fd, ans_fd, count);
     111                        ret = sendfile( this.pipe, fd, ans_fd, count);
     112                        if( ret == -ECONNRESET ) break REQUEST;
    113113
    114114                        if( options.log ) printf("=== Answer sent ===\n");
    115115                }
     116
     117                if( options.log ) printf("=== Connection closed ===\n");
     118                close(fd);
     119                continue CONNECTION;
    116120        }
    117121}
Note: See TracChangeset for help on using the changeset viewer.