Changeset 2441 for trunk/packages/vizservers
- Timestamp:
- Aug 29, 2011, 6:17:00 AM (13 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/packages/vizservers/pymolproxy/pymolproxy.c
r2437 r2441 156 156 * are in the front of the list. */ 157 157 158 int sin, sout , serr;/* Server file descriptors. */158 int sin, sout; /* Server file descriptors. */ 159 159 int cin, cout; /* Client file descriptors. */ 160 160 ReadBuffer client; /* Read buffer for client input. */ … … 1945 1945 int sin[2]; 1946 1946 int sout[2]; 1947 int serr[2];1948 1947 Tcl_Interp *interp; 1949 int child;1948 pid_t child, parent; 1950 1949 PymolProxy proxy; 1951 1950 struct timeval end; … … 1963 1962 } 1964 1963 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. */ 1974 1967 1975 1968 child = fork(); … … 1980 1973 if (child == 0) { 1981 1974 int f; 1975 char path[200]; 1982 1976 1983 1977 /* Child process */ … … 1992 1986 /* Redirect stdin, stdout, and stderr to pipes before execing */ 1993 1987 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 */ 1997 1993 1998 1994 /* Close all other descriptors */ … … 2012 2008 close(sin[0]); 2013 2009 close(sout[1]); 2014 close(serr[1]);2015 2010 2016 2011 #ifdef notdef … … 2021 2016 proxy.sin = sin[1]; 2022 2017 proxy.sout = sout[0]; 2023 proxy.serr = serr[0];2024 2018 proxy.cin = cin; 2025 2019 proxy.cout = cout; … … 2067 2061 // send images back 2068 2062 2069 if (write(cout, "PyMol 1.0\n", 10) != 10) {2070 ERROR("short write of signature");2071 }2072 2073 2063 PollForEvents(&proxy); 2074 2064 2075 2065 close(proxy.cout); 2076 2066 close(proxy.sout); 2077 close(proxy.serr);2078 2067 close(proxy.cin); 2079 2068 close(proxy.sin); … … 2115 2104 { 2116 2105 Tcl_DString clientCmds; 2117 struct pollfd poll Results[4], initPoll;2106 struct pollfd pollFd[3]; 2118 2107 int flags; 2119 2108 … … 2121 2110 fcntl(proxyPtr->cin, F_SETFL, flags|O_NONBLOCK); 2122 2111 2123 flags = fcntl(proxyPtr->serr, F_GETFL);2124 fcntl(proxyPtr->serr, F_SETFL, flags|O_NONBLOCK);2125 2126 2112 flags = fcntl(proxyPtr->sout, F_GETFL); 2127 2113 fcntl(proxyPtr->sout, F_SETFL, flags|O_NONBLOCK); … … 2131 2117 2132 2118 /* 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; 2138 2122 2139 2123 /* Write file descriptors. */ 2140 poll Results[3].fd = proxyPtr->cin; /* Client standard input. */2141 poll Results[3].events = POLLOUT;2124 pollFd[2].fd = proxyPtr->cin; /* Client standard input. */ 2125 pollFd[2].events = POLLOUT; 2142 2126 2143 2127 InitBuffer(&proxyPtr->client, proxyPtr->cout); 2144 2128 InitBuffer(&proxyPtr->server, proxyPtr->sout); 2145 2129 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 2154 2135 Tcl_DStringInit(&clientCmds); 2155 2136 for (;;) { 2156 2137 int timeout, nChannels; 2157 2138 2158 nChannels = (proxyPtr->headPtr != NULL) ? 4 : 3;2139 nChannels = (proxyPtr->headPtr != NULL) ? 3 : 2; 2159 2140 2160 2141 #define PENDING_TIMEOUT 10 /* milliseconds. */ 2161 2142 timeout = (proxyPtr->flags & UPDATE_PENDING) ? PENDING_TIMEOUT : -1; 2162 nChannels = poll(poll Results, nChannels, timeout);2143 nChannels = poll(pollFd, nChannels, timeout); 2163 2144 if (nChannels < 0) { 2164 2145 ERROR("POLL ERROR: %s", strerror(errno)); … … 2171 2152 * the pymol server to block writing to stderr or stdout. 2172 2153 */ 2173 if (poll Results[1].revents & POLLIN) {2154 if (pollFd[1].revents & POLLIN) { /* Server stdout */ 2174 2155 int nBytes; 2175 2156 char *line; … … 2191 2172 } 2192 2173 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 2215 2174 /* We have some descriptors ready. */ 2216 if (poll Results[0].revents & POLLIN) {2175 if (pollFd[0].revents & POLLIN) { /* Client stdout */ 2217 2176 Debug("Reading client stdout\n"); 2218 2177 for (;;) { … … 2269 2228 } 2270 2229 } 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); 2274 2232 } 2275 2233 }
Note: See TracChangeset
for help on using the changeset viewer.