Lines Matching refs:fd
73 #define read(fd, buf, len) recv(fd, (char *) (buf), (int) (len), 0) argument
74 #define write(fd, buf, len) send(fd, (char *) (buf), (int) (len), 0) argument
75 #define close(fd) closesocket(fd) argument
141 static int check_fd(int fd, int for_select) in check_fd() argument
143 if (fd < 0) { in check_fd()
155 if (for_select && fd >= FD_SETSIZE) { in check_fd()
168 ctx->fd = -1; in mbedtls_net_init()
197 ctx->fd = (int) socket(cur->ai_family, cur->ai_socktype, in mbedtls_net_connect()
199 if (ctx->fd < 0) { in mbedtls_net_connect()
204 if (connect(ctx->fd, cur->ai_addr, MSVC_INT_CAST cur->ai_addrlen) == 0) { in mbedtls_net_connect()
209 close(ctx->fd); in mbedtls_net_connect()
246 ctx->fd = (int) socket(cur->ai_family, cur->ai_socktype, in mbedtls_net_bind()
248 if (ctx->fd < 0) { in mbedtls_net_bind()
254 if (setsockopt(ctx->fd, SOL_SOCKET, SO_REUSEADDR, in mbedtls_net_bind()
256 close(ctx->fd); in mbedtls_net_bind()
261 if (bind(ctx->fd, cur->ai_addr, MSVC_INT_CAST cur->ai_addrlen) != 0) { in mbedtls_net_bind()
262 close(ctx->fd); in mbedtls_net_bind()
269 if (listen(ctx->fd, MBEDTLS_NET_LISTEN_BACKLOG) != 0) { in mbedtls_net_bind()
270 close(ctx->fd); in mbedtls_net_bind()
312 if ((fcntl(ctx->fd, F_GETFL) & O_NONBLOCK) != O_NONBLOCK) { in net_would_block()
353 if (getsockopt(bind_ctx->fd, SOL_SOCKET, SO_TYPE, in mbedtls_net_accept()
361 ret = client_ctx->fd = (int) accept(bind_ctx->fd, in mbedtls_net_accept()
367 ret = (int) recvfrom(bind_ctx->fd, buf, sizeof(buf), MSG_PEEK, in mbedtls_net_accept()
393 if (connect(bind_ctx->fd, (struct sockaddr *) &client_addr, n) != 0) { in mbedtls_net_accept()
397 client_ctx->fd = bind_ctx->fd; in mbedtls_net_accept()
398 bind_ctx->fd = -1; /* In case we exit early */ in mbedtls_net_accept()
401 if (getsockname(client_ctx->fd, in mbedtls_net_accept()
403 (bind_ctx->fd = (int) socket(local_addr.ss_family, in mbedtls_net_accept()
405 setsockopt(bind_ctx->fd, SOL_SOCKET, SO_REUSEADDR, in mbedtls_net_accept()
410 if (bind(bind_ctx->fd, (struct sockaddr *) &local_addr, n) != 0) { in mbedtls_net_accept()
448 return ioctlsocket(ctx->fd, FIONBIO, &n); in mbedtls_net_set_block()
450 return fcntl(ctx->fd, F_SETFL, fcntl(ctx->fd, F_GETFL) & ~O_NONBLOCK); in mbedtls_net_set_block()
459 return ioctlsocket(ctx->fd, FIONBIO, &n); in mbedtls_net_set_nonblock()
461 return fcntl(ctx->fd, F_SETFL, fcntl(ctx->fd, F_GETFL) | O_NONBLOCK); in mbedtls_net_set_nonblock()
477 int fd = ctx->fd; in mbedtls_net_poll() local
479 ret = check_fd(fd, 1); in mbedtls_net_poll()
497 FD_SET(fd, &read_fds); in mbedtls_net_poll()
503 FD_SET(fd, &write_fds); in mbedtls_net_poll()
514 ret = select(fd + 1, &read_fds, &write_fds, NULL, in mbedtls_net_poll()
523 if (FD_ISSET(fd, &read_fds)) { in mbedtls_net_poll()
526 if (FD_ISSET(fd, &write_fds)) { in mbedtls_net_poll()
559 int fd = ((mbedtls_net_context *) ctx)->fd; in mbedtls_net_recv() local
561 ret = check_fd(fd, 0); in mbedtls_net_recv()
566 ret = (int) read(fd, buf, len); in mbedtls_net_recv()
603 int fd = ((mbedtls_net_context *) ctx)->fd; in mbedtls_net_recv_timeout() local
605 ret = check_fd(fd, 1); in mbedtls_net_recv_timeout()
611 FD_SET(fd, &read_fds); in mbedtls_net_recv_timeout()
616 ret = select(fd + 1, &read_fds, NULL, NULL, timeout == 0 ? NULL : &tv); in mbedtls_net_recv_timeout()
648 int fd = ((mbedtls_net_context *) ctx)->fd; in mbedtls_net_send() local
650 ret = check_fd(fd, 0); in mbedtls_net_send()
655 ret = (int) write(fd, buf, len); in mbedtls_net_send()
688 if (ctx->fd == -1) { in mbedtls_net_close()
692 close(ctx->fd); in mbedtls_net_close()
694 ctx->fd = -1; in mbedtls_net_close()
702 if (ctx->fd == -1) { in mbedtls_net_free()
706 shutdown(ctx->fd, 2); in mbedtls_net_free()
707 close(ctx->fd); in mbedtls_net_free()
709 ctx->fd = -1; in mbedtls_net_free()