Error PacketPeerUDPWinsock::put_packet(const uint8_t *p_buffer, int p_buffer_size) { ERR_FAIL_COND_V(!peer_addr.is_valid(), ERR_UNCONFIGURED); if (sock_type == IP::TYPE_NONE) sock_type = peer_addr.is_ipv4() ? IP::TYPE_IPV4 : IP::TYPE_IPV6; int sock = _get_socket(); ERR_FAIL_COND_V(sock == -1, FAILED); struct sockaddr_storage addr; size_t addr_size = _set_sockaddr(&addr, peer_addr, peer_port, sock_type); _set_blocking(true); errno = 0; int err; while ((err = sendto(sock, (const char *)p_buffer, p_buffer_size, 0, (struct sockaddr *)&addr, addr_size)) != p_buffer_size) { if (WSAGetLastError() != WSAEWOULDBLOCK) { return FAILED; }; } return OK; }
Error PacketPeerUDPWinsock::listen(int p_port, IP_Address p_bind_address, int p_recv_buffer_size) { ERR_FAIL_COND_V(sockfd != -1, ERR_ALREADY_IN_USE); ERR_FAIL_COND_V(!p_bind_address.is_valid() && !p_bind_address.is_wildcard(), ERR_INVALID_PARAMETER); sock_type = IP::TYPE_ANY; if (p_bind_address.is_valid()) sock_type = p_bind_address.is_ipv4() ? IP::TYPE_IPV4 : IP::TYPE_IPV6; int sock = _get_socket(); if (sock == -1) return ERR_CANT_CREATE; struct sockaddr_storage addr = { 0 }; size_t addr_size = _set_listen_sockaddr(&addr, p_port, sock_type, IP_Address()); if (bind(sock, (struct sockaddr *)&addr, addr_size) == -1) { close(); return ERR_UNAVAILABLE; } blocking = true; printf("UDP Connection listening on port %i\n", p_port); rb.resize(nearest_shift(p_recv_buffer_size)); return OK; }
Error PacketPeerUDPPosix::listen(int p_port, int p_recv_buffer_size){ close(); int sock = _get_socket(); if (sock == -1 ) return ERR_CANT_CREATE; sockaddr_in addr = {0}; addr.sin_family = AF_INET; addr.sin_port = htons(p_port); addr.sin_addr.s_addr = INADDR_ANY; if (bind(sock, (struct sockaddr*)&addr, sizeof(sockaddr_in)) == -1 ) { close(); return ERR_UNAVAILABLE; } printf("UDP Connection listening on port %i bufsize %i \n", p_port,p_recv_buffer_size); rb.resize(nearest_shift(p_recv_buffer_size)); return OK; }
Error PacketPeerUDPPosix::listen(int p_port, IP_Address::AddrType p_address_type, int p_recv_buffer_size) { ERR_FAIL_COND_V(p_address_type != IP_Address::TYPE_IPV4 && p_address_type != IP_Address::TYPE_IPV6, ERR_INVALID_PARAMETER); close(); int sock = _get_socket(p_address_type); if (sock == -1 ) return ERR_CANT_CREATE; sockaddr_storage addr = {0}; size_t addr_size = _set_listen_sockaddr(&addr, p_port, p_address_type, NULL); if (bind(sock, (struct sockaddr*)&addr, addr_size) == -1 ) { close(); return ERR_UNAVAILABLE; } rb.resize(nearest_shift(p_recv_buffer_size)); return OK; }
Error PacketPeerUDPWinsock::put_packet(const uint8_t *p_buffer,int p_buffer_size){ int sock = _get_socket(); ERR_FAIL_COND_V( sock == -1, FAILED ); struct sockaddr_storage addr; size_t addr_size = _set_sockaddr(&addr, peer_addr, peer_port, ip_type); _set_blocking(true); errno = 0; int err; while ( (err = sendto(sock, (const char*)p_buffer, p_buffer_size, 0, (struct sockaddr*)&addr, addr_size)) != p_buffer_size) { if (WSAGetLastError() != WSAEWOULDBLOCK) { return FAILED; }; } return OK; }
Error PacketPeerUDPPosix::put_packet(const uint8_t *p_buffer,int p_buffer_size){ ERR_FAIL_COND_V(peer_addr.type == IP_Address::TYPE_NONE, ERR_UNCONFIGURED); int sock = _get_socket(peer_addr.type); ERR_FAIL_COND_V( sock == -1, FAILED ); struct sockaddr_storage addr; size_t addr_size = _set_sockaddr(&addr, peer_addr, peer_port); errno = 0; int err; while ( (err = sendto(sock, p_buffer, p_buffer_size, 0, (struct sockaddr*)&addr, addr_size)) != p_buffer_size) { if (errno != EAGAIN) { return FAILED; } } return OK; }
Error PacketPeerUDPWinsock::listen(int p_port, int p_recv_buffer_size) { close(); int sock = _get_socket(); if (sock == -1 ) return ERR_CANT_CREATE; struct sockaddr_storage addr = {0}; size_t addr_size = _set_listen_sockaddr(&addr, p_port, ip_type, NULL); if (bind(sock, (struct sockaddr*)&addr, addr_size) == -1 ) { close(); return ERR_UNAVAILABLE; } blocking=true; printf("UDP Connection listening on port %i\n", p_port); rb.resize(nearest_shift(p_recv_buffer_size)); return OK; }
Error PacketPeerUDPPosix::put_packet(const uint8_t *p_buffer,int p_buffer_size){ int sock = _get_socket(); ERR_FAIL_COND_V( sock == -1, FAILED ); struct sockaddr_in addr; addr.sin_family = AF_INET; addr.sin_port = htons(peer_port); addr.sin_addr = *((struct in_addr*)&peer_addr.host); errno = 0; int err; while ( (err = sendto(sock, p_buffer, p_buffer_size, 0, (struct sockaddr*)&addr, sizeof(addr))) != p_buffer_size) { if (errno != EAGAIN) { return FAILED; } } return OK; }
} int accept(int socket, struct sockaddr *restrict address, socklen_t *restrict address_len) { socket_t *s, *new_s = NULL; int res = 0; /* May be kept unassigned if no conn module is available */ /* cppcheck-suppress unassignedVariable */ struct sockaddr_storage tmp; void *addr; uint16_t *port; socklen_t tmp_len; mutex_lock(&_pool_mutex); s = _get_socket(socket); if (s == NULL) { mutex_unlock(&_pool_mutex); errno = ENOTSOCK; return -1; } if (!s->bound) { mutex_unlock(&_pool_mutex); errno = EINVAL; return -1; } switch (s->domain) { case AF_INET: addr = _in_addr_ptr(&tmp); port = _in_port_ptr(&tmp); tmp_len = sizeof(struct sockaddr_in);