Skip to content

Commit b825395

Browse files
committed
PHPC-106: Implement the new poll callback
1 parent 3bb0c8b commit b825395

File tree

1 file changed

+32
-0
lines changed

1 file changed

+32
-0
lines changed

php_phongo.c

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -762,6 +762,37 @@ mongoc_stream_t* phongo_stream_get_base_stream(mongoc_stream_t *stream) /* {{{ *
762762
return (mongoc_stream_t *) stream;
763763
} /* }}} */
764764

765+
ssize_t
766+
phongo_stream_poll (mongoc_stream_poll_t *streams, size_t nstreams, int32_t timeout)
767+
{
768+
php_pollfd *fds = NULL;
769+
size_t i;
770+
ssize_t rval = -1;
771+
772+
fds = emalloc(sizeof(*fds) * nstreams);
773+
for (i = 0; i < nstreams; i++) {
774+
php_socket_t this_fd;
775+
776+
if (php_stream_cast(((php_phongo_stream_socket *)streams[i].stream)->stream, PHP_STREAM_AS_FD_FOR_SELECT | PHP_STREAM_CAST_INTERNAL, (void*)&this_fd, 0) == SUCCESS && this_fd >= 0) {
777+
fds[i].fd = this_fd;
778+
fds[i].events = streams[i].events;
779+
fds[i].revents = 0;
780+
}
781+
}
782+
783+
rval = php_poll2(fds, nstreams, timeout);
784+
785+
if (rval > 0) {
786+
for (i = 0; i < nstreams; i++) {
787+
streams[i].revents = fds[i].revents;
788+
}
789+
}
790+
791+
efree(fds);
792+
793+
return rval;
794+
}
795+
765796
mongoc_stream_t* phongo_stream_initiator(const mongoc_uri_t *uri, const mongoc_host_list_t *host, void *user_data, bson_error_t *error) /* {{{ */
766797
{
767798
php_phongo_stream_socket *base_stream = NULL;
@@ -883,6 +914,7 @@ mongoc_stream_t* phongo_stream_initiator(const mongoc_uri_t *uri, const mongoc_h
883914
base_stream->vtable.setsockopt = phongo_stream_setsockopt;
884915
base_stream->vtable.check_closed = phongo_stream_socket_check_closed;
885916
base_stream->vtable.get_base_stream = phongo_stream_get_base_stream;
917+
base_stream->vtable.poll = phongo_stream_poll;
886918

887919
if (host->family != AF_UNIX) {
888920
int flag = 1;

0 commit comments

Comments
 (0)