#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
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");