intmap *descs_by_fd = NULL; /**< Map of ports to DESC* objects */
static bool console_mode = 0;
-static int console_input, console_output;
+static int console_input = -1, console_output = -1;
static int sock = 0;
#ifdef HAS_OPENSSL
static int sslsock = 0;
}
#ifdef DEBUG
do_rawlog(LT_TRACE, "Sending %d bytes in %d blocks to socket %d",
- cnt, n, d->descriptor);
+ cnt, n, d->outdesc);
#endif
- cnt = writev(d->descriptor, lines, n);
+ cnt = writev(d->outdesc, lines, n);
#ifdef DEBUG
do_rawlog(LT_TRACE, "writev() returned %d", cnt);
#endif
} else
#endif /* HAS_OPENSSL */
{
- cnt = send(d->descriptor, cur->start, cur->nchars, 0);
+ if (d->outdesc == console_output)
+ cnt = write(d->outdesc, cur->start, cur->nchars);
+ else
+ cnt = send(d->outdesc, cur->start, cur->nchars, 0);
if (cnt < 0) {
#ifdef WIN32
if (cnt == SOCKET_ERROR && WSAGetLastError() == WSAEWOULDBLOCK)
} else {
#endif
- got = recv(d->descriptor, tbuf1, sizeof tbuf1, 0);
+ if (d->descriptor == console_input)
+ got = read(d->descriptor, tbuf1, sizeof tbuf1);
+ else
+ got = recv(d->descriptor, tbuf1, sizeof tbuf1, 0);
if (got <= 0) {
/* At this point, select() says there's data waiting to be read from
* the socket, but we shouldn't assume that read() will actually get it
byebye[1].iov_len = 2;
writev(d->outdesc, byebye, 2);
#else
- send(d->outdesc, shutmsg, shutlen, 0);
- send(d->outdesc, (char *) "\r\n", 2, 0);
+ if (d->outdesc == console_outpt) {
+ write(d->outdesc, shutmsg, shutlen);
+ write(d->outdesc, (char *) "\r\n", 2);
+ } else {
+ send(d->outdesc, shutmsg, shutlen, 0);
+ send(d->outdesc, (char *) "\r\n", 2, 0);
+ }
#endif
#ifdef HAS_OPENSSL
} else {
/* From bsd.c */
extern int maxd;
-DESC *initializesock(int s, char *addr, char *ip, int use_ssl);
+DESC *initializesock(int s, int os, char *addr, char *ip, int use_ssl);
/** Re-query lookups that have timed out */
void
do_log(LT_CONN, 0, 0, T("[%d/%s/%s] Connection opened."), resp.fd,
hostname, resp.ipaddr);
set_keepalive(resp.fd);
- initializesock(resp.fd, hostname, resp.ipaddr,
+ initializesock(resp.fd, resp.fd, hostname, resp.ipaddr,
(resp.connected_to == SSLPORT));
}