Changeset 2441 for trunk/packages


Ignore:
Timestamp:
Aug 29, 2011, 6:17:00 AM (13 years ago)
Author:
gah
Message:
 
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/packages/vizservers/pymolproxy/pymolproxy.c

    r2437 r2441  
    156156                                         * are in the front of the list. */
    157157
    158     int sin, sout, serr;                /* Server file descriptors. */
     158    int sin, sout;                      /* Server file descriptors. */
    159159    int cin, cout;                      /* Client file descriptors. */
    160160    ReadBuffer client;                  /* Read buffer for client input. */
     
    19451945    int sin[2];
    19461946    int sout[2];
    1947     int serr[2];
    19481947    Tcl_Interp *interp;
    1949     int child;
     1948    pid_t child, parent;
    19501949    PymolProxy proxy;
    19511950    struct timeval end;
     
    19631962    }
    19641963
    1965     if (pipe(serr) == -1) {
    1966         close(sin[0]);
    1967         close(sin[1]);
    1968         close(sout[0]);
    1969         close(sout[1]);
    1970         return -1;
    1971     }
    1972 
    1973     /* Fork the new process.  Connect i/o to the new socket.  */
     1964    parent = getpid();
     1965
     1966    /* Fork the new process.  Connect I/O to the new socket.  */
    19741967
    19751968    child = fork();
     
    19801973    if (child == 0) {
    19811974        int f;
     1975        char path[200];
    19821976
    19831977        /* Child process */
     
    19921986        /* Redirect stdin, stdout, and stderr to pipes before execing */
    19931987
    1994         dup2(sin[0], 0);  // stdin
    1995         dup2(sout[1],1);  // stdout
    1996         dup2(serr[1],2);  // stderr
     1988        dup2(sin[0],  0);               // stdin
     1989        dup2(sout[1], 1);               // stdout
     1990        sprintf(path, "/tmp/pymol%d/stderr", parent);
     1991        f = open(path, O_WRONLY | O_CREAT | O_TRUNC, 0600);
     1992        dup2(f, 2);                     /* Redirect stderr to a file */
    19971993       
    19981994        /* Close all other descriptors  */       
     
    20122008    close(sin[0]);
    20132009    close(sout[1]);
    2014     close(serr[1]);
    20152010
    20162011#ifdef notdef
     
    20212016    proxy.sin  = sin[1];
    20222017    proxy.sout = sout[0];
    2023     proxy.serr = serr[0];
    20242018    proxy.cin  = cin;
    20252019    proxy.cout = cout;
     
    20672061    //  send images back
    20682062
    2069     if (write(cout, "PyMol 1.0\n", 10) != 10) {
    2070         ERROR("short write of signature");
    2071     }
    2072    
    20732063    PollForEvents(&proxy);
    20742064
    20752065    close(proxy.cout);
    20762066    close(proxy.sout);
    2077     close(proxy.serr);
    20782067    close(proxy.cin);
    20792068    close(proxy.sin);
     
    21152104{
    21162105    Tcl_DString clientCmds;
    2117     struct pollfd pollResults[4], initPoll;
     2106    struct pollfd pollFd[3];
    21182107    int flags;
    21192108
     
    21212110    fcntl(proxyPtr->cin, F_SETFL, flags|O_NONBLOCK);
    21222111
    2123     flags = fcntl(proxyPtr->serr, F_GETFL);
    2124     fcntl(proxyPtr->serr, F_SETFL, flags|O_NONBLOCK);
    2125 
    21262112    flags = fcntl(proxyPtr->sout, F_GETFL);
    21272113    fcntl(proxyPtr->sout, F_SETFL, flags|O_NONBLOCK);
     
    21312117
    21322118    /* Read file descriptors. */
    2133     pollResults[0].fd = proxyPtr->cout; /* Client standard output  */
    2134     pollResults[1].fd = proxyPtr->sout; /* Server standard error.  */
    2135     pollResults[2].fd = proxyPtr->serr; /* Server standard error.  */
    2136     pollResults[0].events = pollResults[1].events =
    2137         pollResults[2].events = POLLIN;
     2119    pollFd[0].fd = proxyPtr->cout;      /* Client standard output  */
     2120    pollFd[1].fd = proxyPtr->sout;      /* Server standard error.  */
     2121    pollFd[0].events = pollFd[1].events = POLLIN;
    21382122
    21392123    /* Write file descriptors. */
    2140     pollResults[3].fd = proxyPtr->cin;  /* Client standard input. */
    2141     pollResults[3].events = POLLOUT;
     2124    pollFd[2].fd = proxyPtr->cin;       /* Client standard input. */
     2125    pollFd[2].events = POLLOUT;
    21422126
    21432127    InitBuffer(&proxyPtr->client, proxyPtr->cout);
    21442128    InitBuffer(&proxyPtr->server, proxyPtr->sout);
    21452129
    2146 #ifdef notdef
    2147     initPoll.fd = proxyPtr->sout;
    2148     initPoll.events = POLLIN;
    2149     if (poll(&initPoll, 1, -1) < 0) {
    2150         ERROR("Initial poll failed: %s", strerror(errno));
    2151         exit(1);
    2152     }
    2153 #endif
     2130    Tcl_Eval(proxyPtr->interp, "reset\n");
     2131    if (write(cout, "PyMol 1.0\n", 10) != 10) {
     2132        ERROR("short write of signature");
     2133    }
     2134
    21542135    Tcl_DStringInit(&clientCmds);
    21552136    for (;;) {
    21562137        int timeout, nChannels;
    21572138
    2158         nChannels =  (proxyPtr->headPtr != NULL) ? 4 : 3;
     2139        nChannels =  (proxyPtr->headPtr != NULL) ? 3 : 2;
    21592140
    21602141#define PENDING_TIMEOUT         10  /* milliseconds. */
    21612142        timeout = (proxyPtr->flags & UPDATE_PENDING) ? PENDING_TIMEOUT : -1;
    2162         nChannels = poll(pollResults, nChannels, timeout);
     2143        nChannels = poll(pollFd, nChannels, timeout);
    21632144        if (nChannels < 0) {
    21642145            ERROR("POLL ERROR: %s", strerror(errno));
     
    21712152         * the pymol server to block writing to stderr or stdout.
    21722153         */
    2173         if (pollResults[1].revents & POLLIN) {
     2154        if (pollFd[1].revents & POLLIN) { /* Server stdout */
    21742155            int nBytes;
    21752156            char *line;
     
    21912172        }
    21922173
    2193         if (pollResults[2].revents & POLLIN) {
    2194             ssize_t nRead;
    2195             char buf[BUFSIZ];
    2196            
    2197             Debug("Reading pymol stderr\n");
    2198             /* pyMol Stderr Connection: pymol standard error output */
    2199            
    2200             nRead = read(pollResults[2].fd, buf, BUFSIZ-1);
    2201             if (nRead <= 0) {
    2202                 ERROR("unexpected read error from server (stderr): %s",
    2203                       strerror(errno));
    2204                 if (errno != EINTR) {
    2205                     ERROR("lost connection (stderr) to pymol server: %s",
    2206                           strerror(errno));
    2207                     goto error;
    2208                 }
    2209             }
    2210             buf[nRead] = '\0';
    2211             Debug("stderr>%s", buf);
    2212             Debug("Done reading pymol stderr\n");
    2213         }
    2214 
    22152174        /* We have some descriptors ready. */
    2216         if (pollResults[0].revents & POLLIN) {
     2175        if (pollFd[0].revents & POLLIN) { /* Client stdout */
    22172176            Debug("Reading client stdout\n");
    22182177            for (;;) {
     
    22692228            }
    22702229        }
    2271         if ((proxyPtr->headPtr != NULL) &&
    2272             (pollResults[3].revents & POLLOUT)) {
    2273             WriteImage(proxyPtr, pollResults[3].fd);
     2230        if ((proxyPtr->headPtr != NULL) && (pollFd[2].revents & POLLOUT)) {
     2231            WriteImage(proxyPtr, pollFd[2].fd);
    22742232        }
    22752233    }
Note: See TracChangeset for help on using the changeset viewer.