Changeset 87:e78ef65c833e for uwsgi.c

Show
Ignore:
Timestamp:
11/11/09 08:21:04 (9 months ago)
Author:
roberto@…
Branch:
default
Message:

better virtualenv support and a bit of protocol timeout fixes

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • uwsgi.c

    r86 r87  
    101101#endif 
    102102 
     103char *pyhome; 
    103104 
    104105char *nl = "\r\n"; 
     
    566567#ifndef UNBIT 
    567568        #ifndef ROCK_SOLID 
    568         while ((i = getopt (argc, argv, "s:p:t:x:d:l:O:v:b:mcaCTPiMhrR:z:w:j:")) != -1) { 
     569        while ((i = getopt (argc, argv, "s:p:t:x:d:l:O:v:b:mcaCTPiMhrR:z:w:j:H:")) != -1) { 
    569570        #else 
    570         while ((i = getopt (argc, argv, "s:p:t:d:l:v:b:aCMhrR:z:j:")) != -1) { 
     571        while ((i = getopt (argc, argv, "s:p:t:d:l:v:b:aCMhrR:z:j:H:")) != -1) { 
    571572        #endif 
    572573#else 
    573         while ((i = getopt (argc, argv, "p:t:mTPiv:b:rMR:Sz:w:C:j:")) != -1) { 
     574        while ((i = getopt (argc, argv, "p:t:mTPiv:b:rMR:Sz:w:C:j:H:")) != -1) { 
    574575#endif 
    575576                switch(i) { 
    576577                        case 'j': 
    577578                                test_module = optarg; 
     579                                break; 
     580                        case 'H': 
     581                                pyhome = optarg; 
    578582                                break; 
    579583#ifdef UNBIT 
     
    697701\t-T\t\tenable threads support (no ROCK_SOLID)\n\ 
    698702\t-M\t\tenable master process manager\n\ 
     703\t-H <path>\tset python home/virtualenv\n\ 
    699704\t-h\t\tthis help\n\ 
    700705\t-d <logfile>  daemonize and log into <logfile>\n", argv[0]); 
     
    722727#endif 
    723728#endif 
    724  
    725 #ifndef UNBIT 
    726 #ifndef ROCK_SOLID 
    727         for (i = optind; i < argc; i++) { 
    728                 fprintf(stderr,"Setting PythonHome to %s...\n", argv[i]); 
    729                 Py_SetPythonHome(argv[i]);               
    730         } 
    731 #endif   
    732 #endif 
     729         
     730 
     731        if (pyhome != NULL) { 
     732                fprintf(stderr,"Setting PythonHome to %s...\n", pyhome); 
     733                Py_SetPythonHome(pyhome);                
     734        } 
    733735 
    734736#ifdef PYTHREE 
     
    10431045                } 
    10441046                rlen = read(wsgi_poll.fd, &wsgi_req, 4) ; 
    1045                 if (rlen != 4){ 
     1047                if (rlen > 0 && rlen < 4) { 
     1048                        i = rlen ; 
     1049                        while(i < 4) { 
     1050                                rlen = poll(&wsgi_poll, 1, socket_timeout*1000) ; 
     1051                                if (rlen < 0) { 
     1052                                        perror("poll()"); 
     1053                                        exit(1); 
     1054                                } 
     1055                                else if (rlen == 0) { 
     1056                                        fprintf(stderr, "timeout waiting for header. skip request.\n"); 
     1057                                        close(wsgi_poll.fd); 
     1058                                        break ; 
     1059                                }        
     1060                                rlen = read(wsgi_poll.fd, (char *)(&wsgi_req)+i, 4-i); 
     1061                                if (rlen <= 0) { 
     1062                                        fprintf(stderr, "broken header. skip request.\n");       
     1063                                        close(wsgi_poll.fd); 
     1064                                        break ; 
     1065                                } 
     1066                                i += rlen; 
     1067                        } 
     1068                        if (i < 4) { 
     1069                                continue; 
     1070                        } 
     1071                } 
     1072                else if (rlen <= 0){ 
    10461073                        fprintf(stderr,"invalid request header size: %d...skip\n", rlen); 
    10471074                        close(wsgi_poll.fd); 
     
    10681095                                break ; 
    10691096                        } 
    1070                         i += read(wsgi_poll.fd, buffer, wsgi_req.size-i); 
     1097                        rlen = read(wsgi_poll.fd, buffer, wsgi_req.size-i); 
     1098                        if (rlen <= 0) { 
     1099                                fprintf(stderr, "broken vars. skip request.\n");              
     1100                                close(wsgi_poll.fd); 
     1101                                break ; 
     1102                        } 
     1103                        i += rlen ; 
    10711104                } 
    10721105