diff --git a/Changelog b/Changelog index 8b441a8..a351f8c 100644 --- a/Changelog +++ b/Changelog @@ -1,3 +1,6 @@ +2019-12-29: +- added: UDP reads can be set to non blocked mode. + 2019-07-21: - fixed: compile will work with older versions of SSL. diff --git a/UDPTCPNetwork.h b/UDPTCPNetwork.h index 7daa136..474e010 100644 --- a/UDPTCPNetwork.h +++ b/UDPTCPNetwork.h @@ -48,6 +48,7 @@ public: int Listen(int port); + int SetBlocked(int bl); long int ReadTimeout(string *srcaddr, char *buffer, long int len, int timeout_ms); long int Read(string *srcaddr, char *buffer, long int len); long int Write(string destaddr, char *buffer, long int len); diff --git a/udp.cc b/udp.cc index 9e3e1a6..f0dfdcf 100644 --- a/udp.cc +++ b/udp.cc @@ -6,6 +6,7 @@ #include #include #include +#include #include #include #include /* close() */ @@ -93,6 +94,16 @@ long int UDP::Read(string *source, char *buffer, long int len) { } +int UDP::SetBlocked(int bl) { + int flags = fcntl(sock, F_GETFL, 0); + + if (bl) flags &= ~O_NONBLOCK; + else flags |= O_NONBLOCK; + + return fcntl(sock, F_SETFL, flags | O_NONBLOCK); +} + + long int UDP::Write(string destaddr, char *buffer, long int len) { int s; int addrlen = sizeof (struct sockaddr_in);