extend poll() protection - release

This commit is contained in:
Philippe G
2020-08-28 19:40:57 -07:00
parent c8054ff9d2
commit ce369638da

View File

@@ -45,6 +45,8 @@ struct buffer *streambuf = &buf;
#define LOCK mutex_lock(streambuf->mutex) #define LOCK mutex_lock(streambuf->mutex)
#define UNLOCK mutex_unlock(streambuf->mutex) #define UNLOCK mutex_unlock(streambuf->mutex)
#define LOCK_L mutex_lock(poll_mutex)
#define UNLOCK_L mutex_unlock(poll_mutex)
static sockfd fd; static sockfd fd;
@@ -188,6 +190,7 @@ static void *stream_thread() {
} else { } else {
LOCK_L;
pollinfo.fd = fd; pollinfo.fd = fd;
pollinfo.events = POLLIN; pollinfo.events = POLLIN;
if (stream.state == SEND_HEADERS) { if (stream.state == SEND_HEADERS) {
@@ -197,12 +200,9 @@ static void *stream_thread() {
UNLOCK; UNLOCK;
mutex_lock(poll_mutex); if (_poll(ssl, &pollinfo, 100)) {
int pending = _poll(ssl, &pollinfo, 100);
mutex_unlock(poll_mutex);
if (pending) {
UNLOCK_L;
LOCK; LOCK;
// check socket has not been closed while in poll // check socket has not been closed while in poll
@@ -355,6 +355,7 @@ static void *stream_thread() {
UNLOCK; UNLOCK;
} else { } else {
UNLOCK_L;
LOG_SDEBUG("poll timeout"); LOG_SDEBUG("poll timeout");
} }
} }
@@ -579,7 +580,6 @@ void stream_sock(u32_t ip, u16_t port, const char *header, size_t header_len, un
bool stream_disconnect(void) { bool stream_disconnect(void) {
bool disc = false; bool disc = false;
mutex_lock(poll_mutex);
LOCK; LOCK;
#if USE_SSL #if USE_SSL
if (ssl) { if (ssl) {
@@ -588,13 +588,14 @@ bool stream_disconnect(void) {
ssl = NULL; ssl = NULL;
} }
#endif #endif
LOCK_L;
if (fd != -1) { if (fd != -1) {
closesocket(fd); closesocket(fd);
fd = -1; fd = -1;
disc = true; disc = true;
} }
UNLOCK_L,
stream.state = STOPPED; stream.state = STOPPED;
UNLOCK; UNLOCK;
mutex_unlock(poll_mutex);
return disc; return disc;
} }