adding UDP setBlock option

origin
steffen 6 years ago
parent 49709b7915
commit 5ecd53c277

@ -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.

@ -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);

@ -6,6 +6,7 @@
#include <sys/socket.h>
#include <netinet/in.h>
#include <arpa/inet.h>
#include <fcntl.h>
#include <netdb.h>
#include <stdio.h>
#include <unistd.h> /* 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);

Loading…
Cancel
Save