Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix ssl read #1501

Closed
wants to merge 4 commits into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
66 changes: 40 additions & 26 deletions src/net.c
Original file line number Diff line number Diff line change
Expand Up @@ -891,42 +891,56 @@ int sockread(char *s, int *len, sock_list *slist, int slistmax, int tclonly)
{
struct timeval t;
fd_set fdr, fdw, fde;
int i, x, maxfd_r, maxfd_w, maxfd_e;
int grab = 511, tclsock = -1, events = 0;
int i, x = 0, maxfd_r, maxfd_w, maxfd_e;
int grab = RECVLINEMAX - 1, tclsock = -1, events = 0;
struct threaddata *td = threaddata();
int maxfd;
#ifdef EGG_TDNS
int fd;
struct dns_thread_node *dtn, *dtn_prev;
#endif

maxfd_r = preparefdset(&fdr, slist, slistmax, tclonly, TCL_READABLE);
/* For each sock, first check SSL_pending(), the check select() */
#ifdef TLS
if (!tclonly)
for (i = 0; i < slistmax; i++)
if (!(slist[i].flags & (SOCK_UNUSED | SOCK_TCL)) && slist[i].ssl && SSL_pending(slist[i].ssl)) {
x = i;
break;
}
if (!x) {
#endif

maxfd_r = preparefdset(&fdr, slist, slistmax, tclonly, TCL_READABLE);
#ifdef EGG_TDNS
for (dtn = dns_thread_head->next; dtn; dtn = dtn->next) {
fd = dtn->fildes[0];
FD_SET(fd, &fdr);
if (fd > maxfd_r)
maxfd_r = fd;
for (dtn = dns_thread_head->next; dtn; dtn = dtn->next) {
fd = dtn->fildes[0];
FD_SET(fd, &fdr);
if (fd > maxfd_r)
maxfd_r = fd;
}
#endif
maxfd_w = preparefdset(&fdw, slist, slistmax, 1, TCL_WRITABLE);
maxfd_e = preparefdset(&fde, slist, slistmax, 1, TCL_EXCEPTION);

maxfd = maxfd_r;
if (maxfd_w > maxfd)
maxfd = maxfd_w;
if (maxfd_e > maxfd)
maxfd = maxfd_e;

/* select() may modify the timeval argument - copy it */
t.tv_sec = td->blocktime.tv_sec;
t.tv_usec = td->blocktime.tv_usec;

x = select((SELECT_TYPE_ARG1) maxfd + 1,
SELECT_TYPE_ARG234 (maxfd_r >= 0 ? &fdr : NULL),
SELECT_TYPE_ARG234 (maxfd_w >= 0 ? &fdw : NULL),
SELECT_TYPE_ARG234 (maxfd_e >= 0 ? &fde : NULL),
SELECT_TYPE_ARG5 &t);
#ifdef TLS
}
#endif
maxfd_w = preparefdset(&fdw, slist, slistmax, 1, TCL_WRITABLE);
maxfd_e = preparefdset(&fde, slist, slistmax, 1, TCL_EXCEPTION);

maxfd = maxfd_r;
if (maxfd_w > maxfd)
maxfd = maxfd_w;
if (maxfd_e > maxfd)
maxfd = maxfd_e;

/* select() may modify the timeval argument - copy it */
t.tv_sec = td->blocktime.tv_sec;
t.tv_usec = td->blocktime.tv_usec;

x = select((SELECT_TYPE_ARG1) maxfd + 1,
SELECT_TYPE_ARG234 (maxfd_r >= 0 ? &fdr : NULL),
SELECT_TYPE_ARG234 (maxfd_w >= 0 ? &fdw : NULL),
SELECT_TYPE_ARG234 (maxfd_e >= 0 ? &fde : NULL),
SELECT_TYPE_ARG5 &t);
if (x == -1)
return -2; /* socket error */
if (x == 0)
Expand Down