g4klx / MMDVMHost

The host program for the MMDVM
GNU General Public License v2.0
379 stars 274 forks source link

UDPSocket renewal #636

Closed jg1uaa closed 4 years ago

jg1uaa commented 4 years ago

Currently there is six variations of (IPv4) UDPSocket.cpp.

to avoid explosion, commonized them.

switch ::fprintf()/LogError by #define HAVE_LOG_H
always display LogInfo("Opening UDP port on") message
delete #include <ifaddrs.h>, this is not needed
no assert(!address.empty()) at constructor

and to support YSFReflector, add multiple socket support. default is #define UDP_SOCKET_MAX 1 so normally this feature is disabled.

added these functions.

CUDPSocket()    (constructor without any parameters)
open(index, af, addr, port)
close(index)

CUDPSocket() means CUDPSocket(address = "", port = 0) index selects socket, address and port is defined at open.

to have compatibility for old codes, these function works as

CUDPSocket(addr, port)  store addr and port to index #0
CUDPSocket(port)    store addr = "" and port to index #0
open()      open with addr and port of index #0, AF_UNSPEC
open(af)    open with addr and port of index #0, specified af
close()     close *all* sockets

read/write operation is for all opened sockets.