Changeset c82af9f


Ignore:
Timestamp:
Jul 16, 2020, 3:22:01 PM (4 years ago)
Author:
Thierry Delisle <tdelisle@…>
Branches:
ADT, arm-eh, ast-experimental, enum, forall-pointer-decay, jacob/cs343-translation, master, new-ast, new-ast-unique-expr, pthread-emulation, qualifiedEnum
Children:
5db836e
Parents:
463cb33
Message:

Moved sendfile to protocol.cfa to reduce compilation time

Location:
benchmark/io/http
Files:
3 edited

Legend:

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

    r463cb33 rc82af9f  
    11#include "protocol.hfa"
    22
     3#define _GNU_SOURCE
     4extern "C" {
     5        #include <fcntl.h>
     6}
    37#include <iofwd.hfa>
    48
     
    8387        return [OK200, false, it, end - it];
    8488}
     89
     90void sendfile( int pipe[2], int fd, int ans_fd, size_t count ) {
     91        off_t offset = 0;
     92        ssize_t ret;
     93        SPLICE1: while(count > 0) {
     94                ret = cfa_splice(ans_fd, &offset, pipe[1], 0p, count, SPLICE_F_MOVE | SPLICE_F_MORE);
     95                if( ret < 0 ) {
     96                        if( errno != EAGAIN && errno != EWOULDBLOCK) continue SPLICE1;
     97                        abort( "splice [0] error: (%d) %s\n", (int)errno, strerror(errno) );
     98                }
     99
     100                count -= ret;
     101                offset += ret;
     102                size_t in_pipe = ret;
     103                SPLICE2: while(in_pipe > 0) {
     104                        ret = cfa_splice(pipe[0], 0p, fd, 0p, in_pipe, SPLICE_F_MOVE | SPLICE_F_MORE);
     105                        if( ret < 0 ) {
     106                                if( errno != EAGAIN && errno != EWOULDBLOCK) continue SPLICE2;
     107                                abort( "splice [1] error: (%d) %s\n", (int)errno, strerror(errno) );
     108                        }
     109                        in_pipe -= ret;
     110                }
     111
     112        }
     113}
  • benchmark/io/http/protocol.hfa

    r463cb33 rc82af9f  
    1414
    1515[HttpCode code, bool closed, * const char file, size_t len] http_read(int fd, []char buffer, size_t len);
     16
     17void sendfile( int pipe[2], int fd, int ans_fd, size_t count );
  • benchmark/io/http/worker.cfa

    r463cb33 rc82af9f  
    11#include "worker.hfa"
    2 
    3 #define __USE_GNU
    42
    53#include <errno.h>
    64#include <stdio.h>
    75#include <string.h>
    8 extern "C" {
    9         #include <fcntl.h>
    10         #include <sys/socket.h>
    11         #include <sys/types.h>
    12         #include <netinet/in.h>
    13 }
     6#include <unistd.h>
    147
    158#include <iofwd.hfa>
     
    3225// Worker Thread
    3326//=============================================================================================
    34 void sendfile( Worker & this, int fd, int ans_fd, size_t count ) {
    35         off_t offset = 0;
    36         ssize_t ret;
    37         SPLICE1: while(count > 0) {
    38                 ret = cfa_splice(ans_fd, &offset, this.pipe[1], 0p, count, SPLICE_F_MOVE | SPLICE_F_MORE);
    39                 if( ret < 0 ) {
    40                         if( errno != EAGAIN && errno != EWOULDBLOCK) continue SPLICE1;
    41                         abort( "splice [0] error: (%d) %s\n", (int)errno, strerror(errno) );
    42                 }
    43 
    44                 count -= ret;
    45                 offset += ret;
    46                 size_t in_pipe = ret;
    47                 SPLICE2: while(in_pipe > 0) {
    48                         ret = cfa_splice(this.pipe[0], 0p, fd, 0p, in_pipe, SPLICE_F_MOVE | SPLICE_F_MORE);
    49                         if( ret < 0 ) {
    50                                 if( errno != EAGAIN && errno != EWOULDBLOCK) continue SPLICE2;
    51                                 abort( "splice [1] error: (%d) %s\n", (int)errno, strerror(errno) );
    52                         }
    53                         in_pipe -= ret;
    54                 }
    55 
    56         }
    57 }
    58 
    5927void ?{}( Worker & this ) {
    6028        ((thread&)this){ "Server Worker Thread", *options.the_cluster };
     
    11179
    11280                        // Send the desired file
    113                         sendfile( this, fd, ans_fd, count);
     81                        sendfile( this.pipe, fd, ans_fd, count);
    11482
    11583                        printf("File sent\n");
Note: See TracChangeset for help on using the changeset viewer.