Skip to content

Commit

Permalink
Fixes krakjoe#733: accept recognizes socket blocking state
Browse files Browse the repository at this point in the history
  • Loading branch information
sirsnyder committed Aug 24, 2017
1 parent 03a9b22 commit d426fb9
Showing 1 changed file with 11 additions and 5 deletions.
16 changes: 11 additions & 5 deletions src/socket.c
Original file line number Diff line number Diff line change
Expand Up @@ -300,15 +300,21 @@ void pthreads_socket_accept(zval *object, zend_class_entry *ce, zval *return_val
ZSTR_VAL(ce->name));
return;
}
php_socket_t acceptedFd = accept(threaded->store.sock->fd, (struct sockaddr*) &sa, &sa_len);

if(acceptedFd < 0) {
if(threaded->store.sock->blocking) {
zend_throw_exception_ex(spl_ce_RuntimeException, 0,
"socket found in invalid state");
}
ZVAL_NULL(return_value);
return;
}
object_init_ex(return_value, ce);

accepted = PTHREADS_FETCH_FROM(Z_OBJ_P(return_value));
accepted->store.sock->fd =
accept(threaded->store.sock->fd, (struct sockaddr*) &sa, &sa_len);

PTHREADS_SOCKET_CHECK(accepted->store.sock);

accepted->store.sock->fd = acceptedFd;
accepted->store.sock->blocking = 1;
accepted->store.sock->domain = ((struct sockaddr*) &sa)->sa_family;
}

Expand Down

0 comments on commit d426fb9

Please sign in to comment.