#include <mt.h>
#include <mtio.h>
-struct stdiofd {
- int fd;
- int sock;
- int timeout;
-};
-
static ssize_t mtread(void *cookie, void *buf, size_t len)
{
struct stdiofd *d = cookie;
return(0);
}
-FILE *mtstdopen(int fd, int issock, int timeout, char *mode)
+FILE *mtstdopen(int fd, int issock, int timeout, char *mode, struct stdiofd **infop)
{
struct stdiofd *d;
FILE *ret;
d->fd = fd;
d->sock = issock;
d->timeout = timeout;
- ret = funstdio(d, r?mtread:NULL, w?mtwrite:NULL, NULL, mtclose);
- if(!ret)
+ if(!(ret = funstdio(d, r?mtread:NULL, w?mtwrite:NULL, NULL, mtclose))) {
free(d);
- else
- fcntl(fd, F_SETFL, fcntl(fd, F_GETFL) | O_NONBLOCK);
+ return(NULL);
+ }
+ fcntl(fd, F_SETFL, fcntl(fd, F_GETFL) | O_NONBLOCK);
+ if(infop)
+ *infop = d;
return(ret);
}
#define EV_READ 1
#define EV_WRITE 2
+struct stdiofd {
+ int fd;
+ int sock;
+ int timeout;
+};
+
int block(int fd, int ev, time_t to);
int ioloop(void);
void exitioloop(int status);
-FILE *mtstdopen(int fd, int issock, int timeout, char *mode);
+FILE *mtstdopen(int fd, int issock, int timeout, char *mode, struct stdiofd **infop);
void mtiopipe(FILE **read, FILE **write);
#endif
self.method = env.get("REQUEST_METHOD")
self.uri = env.get("REQUEST_URI")
self.host = env.get("HTTP_HOST")
+ self.script_uri = env.get("SCRIPT_NAME")
+ self.script_path = env.get("SCRIPT_FILENAME")
+ self.pathinfo = env.get("PATH_INFO")
+ self.querystring = env.get("QUERY_STRING")
self.remoteaddr = env.get("REMOTE_ADDR")
self.remoteport = env.get("REMOTE_PORT")
+ self.scheme = env.get("wsgi.url_scheme")
class reqfinish(pdm.perf.finishevent):
def __init__(self, start, aborted, status):
import pdm.perf
except:
pdm = None
+try:
+ import time
+ clock_thread = time.CLOCK_THREAD_CPUTIME_ID
+except:
+ clock_thread = None
reqstat = {}
self.method = env.get("REQUEST_METHOD")
self.uri = env.get("REQUEST_URI")
self.host = env.get("HTTP_HOST")
+ self.script_uri = env.get("SCRIPT_NAME")
+ self.script_path = env.get("SCRIPT_FILENAME")
+ self.pathinfo = env.get("PATH_INFO")
+ self.querystring = env.get("QUERY_STRING")
self.remoteaddr = env.get("REMOTE_ADDR")
self.remoteport = env.get("REMOTE_PORT")
+ self.scheme = env.get("wsgi.url_scheme")
+ if clock_thread is not None:
+ self.icpu = time.clock_gettime(clock_thread)
class reqfinish(pdm.perf.finishevent):
def __init__(self, start, aborted, status):
super().__init__(start, aborted)
self.status = status
+ self.cputime = 0
+ if clock_thread is not None:
+ self.cputime = time.clock_gettime(clock_thread) - start.icpu
class request(object):
def __init__(self, env):
data = defdata;
data.req = req;
gettimeofday(&data.start, NULL);
- cl = mtstdopen(fd, 1, 600, "r+");
+ cl = mtstdopen(fd, 1, 600, "r+", NULL);
if(socketpair(PF_UNIX, SOCK_STREAM, 0, pfds))
goto out;
- hd = mtstdopen(pfds[1], 1, 600, "r+");
+ hd = mtstdopen(pfds[1], 1, 600, "r+", NULL);
if(sendreq(ch, req, pfds[0])) {
close(pfds[0]);
goto out;
char buf[8192];
sfd = reconn();
- is = mtstdopen(fd, 1, 60, "r+");
- os = mtstdopen(sfd, 1, 600, "r+");
+ is = mtstdopen(fd, 1, 60, "r+", NULL);
+ os = mtstdopen(sfd, 1, 600, "r+", NULL);
outi = NULL;
mtiopipe(&outi, &outo); mtiopipe(&erri, &erro);
- mustart(outplex, mtstdopen(dup(sfd), 1, 600, "r+"), outo, FCGI_STDOUT, erro, FCGI_STDERR, NULL);
+ mustart(outplex, mtstdopen(dup(sfd), 1, 600, "r+", NULL), outo, FCGI_STDOUT, erro, FCGI_STDERR, NULL);
mustart(errhandler, erri);
if(begreq(os, 1))
struct hthead *resp;
sfd = reconn();
- is = mtstdopen(fd, 1, 60, "r+");
- os = mtstdopen(sfd, 1, 600, "r+");
+ is = mtstdopen(fd, 1, 60, "r+", NULL);
+ os = mtstdopen(sfd, 1, 600, "r+", NULL);
bufinit(head);
mkcgienv(req, &head);
if(sendreq(plex, req, pfds[0]))
break;
close(pfds[0]);
- out = mtstdopen(pfds[1], 1, 600, "r+");
+ out = mtstdopen(pfds[1], 1, 600, "r+", NULL);
if(getheader(req, "content-type") != NULL) {
if((hd = getheader(req, "content-length")) != NULL) {
memset(&conn, 0, sizeof(conn));
memset(&tcp, 0, sizeof(tcp));
- in = mtstdopen(fd, 1, 60, "r+");
+ in = mtstdopen(fd, 1, 60, "r+", NULL);
conn.pdata = &tcp;
conn.initreq = initreq;
tcp.fd = fd;
sfile = NULL;
contype = NULL;
- out = mtstdopen(fd, 1, 60, "r+");
+ out = mtstdopen(fd, 1, 60, "r+", NULL);
if((file = getheader(req, "X-Ash-File")) == NULL) {
flog(LOG_ERR, "psendfile: needs to be called with the X-Ash-File header");