Public feed
#602347
Socket = socket(AF_INET, SOCK_DGRAM, IPPROTO_UDP);
if(Socket == INVALID_SOCKET)
throw UDPSenderException("UDPSender Socket() exception");
// Set blocking / nonblocking mode
u_long mode = (m_block ? 0 : 1);
int ret = ioctlsocket(Socket, FIONBIO, &mode );
if(ret != 0)
{
closesocket(Socket);
Socket = INVALID_SOCKET;
throw UDPSenderException("UDPSender ioctlsocket() exception");
}
// ~The addr structure should be ready already
if( bind(Socket, (struct sockaddr*)&SendAddr, sizeof(SendAddr)) != 0)
{
closesocket(Socket);
Socket = INVALID_SOCKET;
int ret = WSAGetLastError();
if(ret == WSAEADDRINUSE)
{
throw UDPSenderException("UDPSender Bind() Address in use");
}
throw UDPSenderException("UDPSender Bind() error");
}
********************************
int sa_len = sizeof(sockaddr_in);
int ret = sendto(Socket, udp.bb.contents(), udp.bb.size(),
0, (sockaddr*)&udp.addr, sa_len);
if(ret <= 0)
{
int err = WSAGetLastError();
if(!m_block)
{
if(err == WSAEWOULDBLOCK)
return false;
}
char buf[50];
sprintf(buf, "Code: %d", err);
throw UDPSenderException(std::string("UDPSender sendto() exception") + buf);
}