Ignore:
Timestamp:
Jun 4, 2022, 1:12:56 PM (22 months ago)
Author:
Thierry Delisle <tdelisle@…>
Branches:
ADT, ast-experimental, master, pthread-emulation, qualifiedEnum
Children:
ce98816
Parents:
153570d
Message:

Moved socket creation to a different file.
Makefile now has debug symbol.
Pipes are now closed earlier for a cleaner exit.

File:
1 edited

Legend:

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

    r153570d rc4b10e2  
    2323#include "filecache.hfa"
    2424#include "options.hfa"
     25#include "socket.hfa"
    2526#include "worker.hfa"
    2627
     
    195196//============================================================================================='
    196197int main( int argc, char * argv[] ) {
     198        int ret;
    197199        __sighandler_t s = 1p;
    198200        signal(SIGPIPE, s);
     
    226228        // Open Socket
    227229        sout | getpid() | ": Listening on port" | options.socket.port;
    228         int server_fd = socket(AF_INET, SOCK_STREAM, 0);
    229         if(server_fd < 0) {
    230                 abort( "socket error: (%d) %s\n", (int)errno, strerror(errno) );
    231         }
    232 
    233         int ret = 0;
     230
    234231        struct sockaddr_in address;
    235         int addrlen = sizeof(address);
    236         memset( (char *)&address, '\0' );
    237         address.sin_family = AF_INET;
    238         address.sin_addr.s_addr = htonl(INADDR_ANY);
    239         address.sin_port = htons( options.socket.port );
    240 
    241         int waited = 0;
    242         for() {
    243                 int sockfd = server_fd;
    244                 __CONST_SOCKADDR_ARG addr;
    245                 addr.__sockaddr__ = (struct sockaddr *)&address;
    246                 socklen_t addrlen = sizeof(address);
    247                 ret = bind( sockfd, addr, addrlen );
    248                 if(ret < 0) {
    249                         if(errno == EADDRINUSE) {
    250                                 if(waited == 0) {
    251                                         if(!options.interactive) abort | "Port already in use in non-interactive mode. Aborting";
    252                                         sout | "Waiting for port";
    253                                 } else {
    254                                         sout | "\r" | waited | nonl;
    255                                         flush( sout );
    256                                 }
    257                                 waited ++;
    258                                 sleep( 1`s );
    259                                 continue;
    260                         }
    261                         abort( "bind error: (%d) %s\n", (int)errno, strerror(errno) );
    262                 }
    263                 break;
    264         }
    265 
    266         ret = listen( server_fd, options.socket.backlog );
    267         if(ret < 0) {
    268                 abort( "listen error: (%d) %s\n", (int)errno, strerror(errno) );
    269         }
     232        int addrlen = prepaddr(address);
     233
     234        int server_fd = listener(address, addrlen);
    270235
    271236        //===================
     
    361326                                sout | "Stopping connection threads..." | nonl; flush( sout );
    362327                                for(i; options.clopts.nworkers) {
     328                                        for(j; 2) {
     329                                                ret = close(workers[i].pipe[j]);
     330                                                if(ret < 0) abort( "close pipe %d error: (%d) %s\n", j, (int)errno, strerror(errno) );
     331                                        }
    363332                                        join(workers[i]);
    364333                                }
     
    384353                sout | "done";
    385354
    386                 sout | "Closing splice fds..." | nonl; flush( sout );
    387                 for(i; pipe_cnt) {
    388                         ret = close( fds[pipe_off + i] );
    389                         if(ret < 0) {
    390                                 abort( "close pipe error: (%d) %s\n", (int)errno, strerror(errno) );
    391                         }
    392                 }
     355                // sout | "Closing splice fds..." | nonl; flush( sout );
     356                // for(i; pipe_cnt) {
     357                //      ret = close( fds[pipe_off + i] );
     358                //      if(ret < 0) {
     359                //              abort( "close pipe error: (%d) %s\n", (int)errno, strerror(errno) );
     360                //      }
     361                // }
    393362                free(fds);
    394363                sout | "done";
Note: See TracChangeset for help on using the changeset viewer.