Lines Matching refs:sock

63 	php_netstream_data_t *sock = (php_netstream_data_t*)stream->abstract;  in php_sockop_write()  local
67 if (!sock || sock->socket == -1) { in php_sockop_write()
71 if (sock->timeout.tv_sec == -1) in php_sockop_write()
74 ptimeout = &sock->timeout; in php_sockop_write()
77 …didwrite = send(sock->socket, buf, XP_SOCK_BUF_SIZE(count), (sock->is_blocked && ptimeout) ? MSG_D… in php_sockop_write()
83 if (sock->is_blocked && (err == EWOULDBLOCK || err == EAGAIN)) { in php_sockop_write()
86 sock->timeout_event = 0; in php_sockop_write()
89 retval = php_pollfd_for(sock->socket, POLLOUT, ptimeout); in php_sockop_write()
92 sock->timeout_event = 1; in php_sockop_write()
121 static void php_sock_stream_wait_for_data(php_stream *stream, php_netstream_data_t *sock) in php_sock_stream_wait_for_data() argument
126 if (!sock || sock->socket == -1) { in php_sock_stream_wait_for_data()
130 sock->timeout_event = 0; in php_sock_stream_wait_for_data()
132 if (sock->timeout.tv_sec == -1) in php_sock_stream_wait_for_data()
135 ptimeout = &sock->timeout; in php_sock_stream_wait_for_data()
138 retval = php_pollfd_for(sock->socket, PHP_POLLREADABLE, ptimeout); in php_sock_stream_wait_for_data()
141 sock->timeout_event = 1; in php_sock_stream_wait_for_data()
153 php_netstream_data_t *sock = (php_netstream_data_t*)stream->abstract; in php_sockop_read() local
157 if (!sock || sock->socket == -1) { in php_sockop_read()
161 if (sock->is_blocked) { in php_sockop_read()
162 php_sock_stream_wait_for_data(stream, sock); in php_sockop_read()
163 if (sock->timeout_event) in php_sockop_read()
167 …nr_bytes = recv(sock->socket, buf, XP_SOCK_BUF_SIZE(count), (sock->is_blocked && sock->timeout.tv_… in php_sockop_read()
186 php_netstream_data_t *sock = (php_netstream_data_t*)stream->abstract; in php_sockop_close() local
191 if (!sock) { in php_sockop_close()
198 if (sock->socket == -1) in php_sockop_close()
199 sock->socket = SOCK_ERR; in php_sockop_close()
201 if (sock->socket != SOCK_ERR) { in php_sockop_close()
204 shutdown(sock->socket, SHUT_RD); in php_sockop_close()
213 n = php_pollfd_for_ms(sock->socket, POLLOUT, 500); in php_sockop_close()
216 closesocket(sock->socket); in php_sockop_close()
217 sock->socket = SOCK_ERR; in php_sockop_close()
222 pefree(sock, php_stream_is_persistent(stream)); in php_sockop_close()
230 php_netstream_data_t *sock = (php_netstream_data_t*)stream->abstract; in php_sockop_flush()
231 return fsync(sock->socket); in php_sockop_flush()
241 php_netstream_data_t *sock = (php_netstream_data_t*)stream->abstract; in php_sockop_stat()
243 return zend_fstat(sock->socket, &ssb->sb); in php_sockop_stat()
247 static inline int sock_sendto(php_netstream_data_t *sock, const char *buf, size_t buflen, int flags, in sock_sendto() argument
253 ret = sendto(sock->socket, buf, XP_SOCK_BUF_SIZE(buflen), flags, addr, XP_SOCK_BUF_SIZE(addrlen)); in sock_sendto()
258 …return ((ret = send(sock->socket, buf, buflen > INT_MAX ? INT_MAX : (int)buflen, flags)) == SOCK_C… in sock_sendto()
260 return ((ret = send(sock->socket, buf, buflen, flags)) == SOCK_CONN_ERR) ? -1 : ret; in sock_sendto()
264 static inline int sock_recvfrom(php_netstream_data_t *sock, char *buf, size_t buflen, int flags, in sock_recvfrom() argument
275 ret = recvfrom(sock->socket, buf, XP_SOCK_BUF_SIZE(buflen), flags, (struct sockaddr*)&sa, &sl); in sock_recvfrom()
290 ret = recv(sock->socket, buf, XP_SOCK_BUF_SIZE(buflen), flags); in sock_recvfrom()
300 php_netstream_data_t *sock = (php_netstream_data_t*)stream->abstract; in php_sockop_set_option() local
303 if (!sock) { in php_sockop_set_option()
315 if (sock->timeout.tv_sec == -1) { in php_sockop_set_option()
319 tv = sock->timeout; in php_sockop_set_option()
326 if (sock->socket == -1) { in php_sockop_set_option()
328 } else if (php_pollfd_for(sock->socket, PHP_POLLREADABLE|POLLPRI, &tv) > 0) { in php_sockop_set_option()
336 ret = recv(sock->socket, &buf, sizeof(buf), MSG_PEEK); in php_sockop_set_option()
347 oldmode = sock->is_blocked; in php_sockop_set_option()
348 if (SUCCESS == php_set_sock_blocking(sock->socket, value)) { in php_sockop_set_option()
349 sock->is_blocked = value; in php_sockop_set_option()
355 sock->timeout = *(struct timeval*)ptrparam; in php_sockop_set_option()
356 sock->timeout_event = 0; in php_sockop_set_option()
360 add_assoc_bool((zval *)ptrparam, "timed_out", sock->timeout_event); in php_sockop_set_option()
361 add_assoc_bool((zval *)ptrparam, "blocked", sock->is_blocked); in php_sockop_set_option()
370 xparam->outputs.returncode = (listen(sock->socket, xparam->inputs.backlog) == 0) ? 0: -1; in php_sockop_set_option()
374 xparam->outputs.returncode = php_network_get_sock_name(sock->socket, in php_sockop_set_option()
382 xparam->outputs.returncode = php_network_get_peer_name(sock->socket, in php_sockop_set_option()
394 xparam->outputs.returncode = sock_sendto(sock, in php_sockop_set_option()
415 xparam->outputs.returncode = sock_recvfrom(sock, in php_sockop_set_option()
438 xparam->outputs.returncode = shutdown(sock->socket, shutdown_how[xparam->how]); in php_sockop_set_option()
454 php_netstream_data_t *sock = (php_netstream_data_t*)stream->abstract; in php_sockop_cast() local
456 if (!sock) { in php_sockop_cast()
463 *(FILE**)ret = fdopen(sock->socket, stream->mode); in php_sockop_cast()
473 *(php_socket_t *)ret = sock->socket; in php_sockop_cast()
612 static inline int php_tcp_sockop_bind(php_stream *stream, php_netstream_data_t *sock, in php_tcp_sockop_bind() argument
624sock->socket = socket(PF_UNIX, stream->ops == &php_stream_unix_socket_ops ? SOCK_STREAM : SOCK_DGR… in php_tcp_sockop_bind()
626 if (sock->socket == SOCK_ERR) { in php_tcp_sockop_bind()
637 return bind(sock->socket, (const struct sockaddr *)&unix_addr, in php_tcp_sockop_bind()
677 sock->socket = php_network_bind_socket_to_local_addr(host, portno, in php_tcp_sockop_bind()
688 return sock->socket == -1 ? -1 : 0; in php_tcp_sockop_bind()
691 static inline int php_tcp_sockop_connect(php_stream *stream, php_netstream_data_t *sock, in php_tcp_sockop_connect() argument
705sock->socket = socket(PF_UNIX, stream->ops == &php_stream_unix_socket_ops ? SOCK_STREAM : SOCK_DGR… in php_tcp_sockop_connect()
707 if (sock->socket == SOCK_ERR) { in php_tcp_sockop_connect()
716 ret = php_network_connect_socket(sock->socket, in php_tcp_sockop_connect()
759 sock->socket = php_network_connect_socket_to_host(host, portno, in php_tcp_sockop_connect()
770 ret = sock->socket == -1 ? -1 : 0; in php_tcp_sockop_connect()
792 static inline int php_tcp_sockop_accept(php_stream *stream, php_netstream_data_t *sock, in php_tcp_sockop_accept() argument
799 clisock = php_network_accept_incoming(sock->socket, in php_tcp_sockop_accept()
817 memcpy(clisockdata, sock, sizeof(*clisockdata)); in php_tcp_sockop_accept()
835 php_netstream_data_t *sock = (php_netstream_data_t*)stream->abstract; in php_tcp_sockop_set_option() local
845 xparam->outputs.returncode = php_tcp_sockop_connect(stream, sock, xparam); in php_tcp_sockop_set_option()
849 xparam->outputs.returncode = php_tcp_sockop_bind(stream, sock, xparam); in php_tcp_sockop_set_option()
854 xparam->outputs.returncode = php_tcp_sockop_accept(stream, sock, xparam STREAMS_CC); in php_tcp_sockop_set_option()
872 php_netstream_data_t *sock; in php_stream_generic_socket_factory() local
893 sock = pemalloc(sizeof(php_netstream_data_t), persistent_id ? 1 : 0); in php_stream_generic_socket_factory()
894 memset(sock, 0, sizeof(php_netstream_data_t)); in php_stream_generic_socket_factory()
896 sock->is_blocked = 1; in php_stream_generic_socket_factory()
897 sock->timeout.tv_sec = FG(default_socket_timeout); in php_stream_generic_socket_factory()
898 sock->timeout.tv_usec = 0; in php_stream_generic_socket_factory()
902 sock->socket = -1; in php_stream_generic_socket_factory()
904 stream = php_stream_alloc_rel(ops, sock, persistent_id, "r+"); in php_stream_generic_socket_factory()
907 pefree(sock, persistent_id ? 1 : 0); in php_stream_generic_socket_factory()