nidas v1.2.3
Socket.h
Go to the documentation of this file.
1// -*- mode: C++; indent-tabs-mode: nil; c-basic-offset: 4; tab-width: 4; -*-
2// vim: set shiftwidth=4 softtabstop=4 expandtab:
3/*
4 ********************************************************************
5 ** NIDAS: NCAR In-situ Data Acquistion Software
6 **
7 ** 2006, Copyright University Corporation for Atmospheric Research
8 **
9 ** This program is free software; you can redistribute it and/or modify
10 ** it under the terms of the GNU General Public License as published by
11 ** the Free Software Foundation; either version 2 of the License, or
12 ** (at your option) any later version.
13 **
14 ** This program is distributed in the hope that it will be useful,
15 ** but WITHOUT ANY WARRANTY; without even the implied warranty of
16 ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 ** GNU General Public License for more details.
18 **
19 ** The LICENSE.txt file accompanying this software contains
20 ** a copy of the GNU General Public License. If it is not found,
21 ** write to the Free Software Foundation, Inc.,
22 ** 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
23 **
24 ********************************************************************
25*/
26/*
27
28 C++ classes supporting TCP, UDP and Unix sockets.
29
30*/
31
32#ifndef NIDAS_UTIL_SOCKET_H
33#define NIDAS_UTIL_SOCKET_H
34
35#include "Inet4SocketAddress.h"
37#include "Inet4PacketInfo.h"
38#include "UnixSocketAddress.h"
39#include "Inet4Address.h"
40#include "IOException.h"
41#include "EOFException.h"
42#include "DatagramPacket.h"
43
44#include <sys/types.h>
45#include <sys/socket.h>
46#include <sys/uio.h>
47
48#include <net/if.h> // IFF_* bits for network interface flags
49
50#include <netinet/in.h>
51#include <ctime>
52#include <cassert>
53
54#include <vector>
55
56namespace nidas { namespace util {
57
58class Socket;
59
77public:
78
82 SocketImpl(int domain,int type);
83
87 SocketImpl(int fd, const SocketAddress& remoteaddr);
88
92 SocketImpl(const SocketImpl& x);
93
98
100
101 int getFd() const { return _fd; }
102
107 int getDomain() const { return _sockdomain; }
108
109 void setBacklog(int val) { _backlog = val; }
110
117 {
118 return *_localaddr;
119 }
120
126 int getLocalPort() const
127 {
128 return _localaddr->getPort();
129 }
130
137 {
138 return *_remoteaddr;
139 }
140
146 int getRemotePort() const
147 {
148 return _remoteaddr->getPort();
149 }
150
151 void setReuseAddress(bool val) { _reuseaddr = val; }
152
156 void setNonBlocking(bool val);
157
161 bool isNonBlocking() const;
162
170 void setTcpNoDelay(bool val);
171
178 bool getTcpNoDelay();
179
187 void setTimeout(int val);
188
189 int getTimeout() const;
190
196 void setKeepAlive(bool val);
197
203 bool getKeepAlive() const;
204
226 void setKeepAliveIdleSecs(int val);
227
235 int getKeepAliveIdleSecs() const;
236
243 int getInQueueSize() const;
244
251 int getOutQueueSize() const;
252
256 void close();
257
261 void bind(int port);
262
266 void bind(const Inet4Address& addr, int port);
267
271 void bind(const SocketAddress& sockaddr);
272
276 void listen();
277
281 Socket* accept();
282
287 void connect(const std::string& dest, int port);
288
292 void connect(const Inet4Address& addr, int port);
293
297 void connect(const SocketAddress& addr);
298
302 void receive(DatagramPacketBase& packet);
303
307 void receive(DatagramPacketBase& packet, Inet4PacketInfo& info, int flags=0);
308
317 size_t recv(void* buf, size_t len, int flags=0);
318
322 size_t recvfrom(void* buf, size_t len, int flags, SocketAddress& from);
323
327 void send(const DatagramPacketBase& packet,int flags=0);
328
342 size_t send(const void* buf, size_t len, int flags = 0);
343
347 size_t send(const struct iovec* iov, int iovcnt, int flags = 0);
348
352 size_t sendto(const void* buf, size_t len, int flags,
353 const SocketAddress& to);
354
358 size_t sendto(const struct iovec* iov, int iovcnt, int flags,
359 const SocketAddress& to);
360
374 void sendall(const void* buf, size_t len, int flags = 0);
375
381 void joinGroup(Inet4Address groupAddr);
382
383 /*
384 void joinGroup(Inet4Address groupAddr,Inet4Address iaddr) throw(IOException);
385 */
386
396 void joinGroup(Inet4Address groupAddr, const Inet4NetworkInterface&);
397
403 void leaveGroup(Inet4Address groupAddr);
404
410 void leaveGroup(Inet4Address groupAddr, const Inet4NetworkInterface& iaddr);
411
415 void setReceiveBufferSize(int size);
416
421
425 void setSendBufferSize(int size);
426
430 int getSendBufferSize();
431
435 void setTimeToLive(int val);
436
440 int getTimeToLive() const;
441
451 void setPktInfo(bool val);
452
453 bool getPktInfo() const
454 {
455 return _pktInfo;
456 }
457
470 void setMulticastLoop(bool val);
471
475 bool getMulticastLoop() const;
476
480 void setInterface(Inet4Address maddr, const Inet4NetworkInterface& iaddr);
481
485 void setInterface(Inet4Address iaddr);
486
491
495 Inet4NetworkInterface getInterface(const std::string& name) const;
496
501
505 std::list<Inet4NetworkInterface> getInterfaces() const;
506
513 void setBroadcastEnable(bool val);
514
518 bool getBroadcastEnable() const;
519
520protected:
521
526 int _fd;
530 struct timespec _timeout;
531
533
539 void getLocalAddr();
540
546 void getRemoteAddr();
547};
548
573class Socket {
574public:
575
586 Socket(int domain=AF_INET);
587
594 Socket(const Inet4Address& addr,int port);
595
603 Socket(const std::string& host, int port);
604
612 Socket(const SocketAddress& addr);
613
621 Socket(int fd, const SocketAddress& raddr);
622
623 ~Socket() throw() {
624 }
625
629 void close()
630 {
631 _impl.close();
632 }
633
640 static std::vector<Socket*> createSocketPair(int type=SOCK_STREAM);
641
649 void setTimeout(int val) { _impl.setTimeout(val); }
650
658 void setNonBlocking(bool val)
659 {
661 }
662
666 bool isNonBlocking() const
667 {
668 return _impl.isNonBlocking();
669 }
670
674 void setTcpNoDelay(bool val)
675 {
676 _impl.setTcpNoDelay(val);
677 }
678
683 {
684 return _impl.getTcpNoDelay();
685 }
686
692 void setKeepAlive(bool val)
693 {
694 _impl.setKeepAlive(val);
695 }
696
703 {
704 return _impl.getKeepAlive();
705 }
706
729 {
731 }
732
741 {
743 }
744
748 int getInQueueSize() const
749 {
750 return _impl.getInQueueSize();
751 }
752
756 int getOutQueueSize() const
757 {
758 return _impl.getOutQueueSize();
759 }
760
766 std::list<Inet4NetworkInterface> getInterfaces() const
767 {
768 return _impl.getInterfaces();
769 }
770
777 void connect(const std::string& host,int port)
778 {
779 _impl.connect(host,port);
780 }
781
787 void connect(const Inet4Address& addr, int port)
788 {
789 _impl.connect(addr,port);
790 }
791
797 void connect(const SocketAddress& addr)
798 {
799 _impl.connect(addr);
800 }
801
805 int getFd() const
806 {
807 return _impl.getFd();
808 }
809
813 size_t recv(void* buf, size_t len, int flags = 0)
814 {
815 return _impl.recv(buf,len,flags);
816 }
817
826 size_t send(const void* buf, size_t len, int flags=MSG_NOSIGNAL)
827 {
828 return _impl.send(buf,len,flags);
829 }
830
834 size_t send(const struct iovec* iov, int iovcnt, int flags=MSG_NOSIGNAL)
835 {
836 return _impl.send(iov,iovcnt,flags);
837 }
838
851 void sendall(const void* buf, size_t len, int flags=MSG_NOSIGNAL)
852 {
853 return _impl.sendall(buf,len,flags);
854 }
855
859 void setReceiveBufferSize(int size)
860 {
862 }
863
868 {
870 }
871
875 void setSendBufferSize(int size)
876 {
878 }
879
884 {
885 return _impl.getSendBufferSize();
886 }
887
894 {
896 }
897
903 int getRemotePort() const {
904 return _impl.getRemotePort();
905 }
906
913 {
915 }
916
922 int getLocalPort() const {
923 return _impl.getLocalPort();
924 }
925
926 int getDomain() const
927 {
928 return _impl.getDomain();
929 }
930
931protected:
933};
934
982public:
983
992 ServerSocket(int port=0,int backlog=10);
993
1000 ServerSocket(const Inet4Address& bindAddr, int port, int backlog=10);
1001
1008 ServerSocket(const SocketAddress& bindAddr, int backlog=10);
1009
1017 }
1018
1019 int getFd() const {
1020 return _impl.getFd();
1021 }
1022
1028 void close();
1029
1046 {
1047 return _impl.accept();
1048 }
1049
1054 {
1056 }
1057
1062 {
1063 return _impl.getReceiveBufferSize();
1064 }
1065
1069 void setSendBufferSize(int size)
1070 {
1072 }
1073
1078 {
1079 return _impl.getSendBufferSize();
1080 }
1081
1088 {
1090 }
1091
1095 int getLocalPort() const {
1096 return _impl.getLocalPort();
1097 }
1098
1099 int getDomain() const {
1100 return _impl.getDomain();
1101 }
1102
1106 void setNonBlocking(bool val)
1107 {
1108 _impl.setNonBlocking(val);
1109 }
1110
1114 bool isNonBlocking() const
1115 {
1116 return _impl.isNonBlocking();
1117 }
1118
1119protected:
1121
1122};
1123
1179public:
1180
1187
1197 DatagramSocket(int port);
1198
1208 DatagramSocket(const Inet4Address& addr, int port);
1209
1219 DatagramSocket(const SocketAddress& addr);
1220
1226 virtual ~DatagramSocket() throw()
1227 {
1228 }
1229
1233 void close()
1234 {
1235 _impl.close();
1236 }
1237
1245 void setTimeout(int val) {
1246 _impl.setTimeout(val);
1247 }
1248
1257 void connect(const std::string& host, int port)
1258 {
1259 _impl.connect(host,port);
1260 }
1261
1269 void connect(const Inet4Address& addr, int port)
1270 {
1271 _impl.connect(addr,port);
1272 }
1273
1281 void connect(const SocketAddress& addr)
1282 {
1283 _impl.connect(addr);
1284 }
1285
1294 void bind(const Inet4Address& addr, int port)
1295 {
1296 _impl.bind(addr,port);
1297 }
1298
1307 void bind(const SocketAddress& addr)
1308 {
1309 _impl.bind(addr);
1310 }
1311
1312 int getFd() const {
1313 return _impl.getFd();
1314 }
1315
1324 {
1325 _impl.receive(packet);
1326 }
1327
1340 void receive(DatagramPacketBase& packet, Inet4PacketInfo& info, int flags=0)
1341 {
1342 _impl.receive(packet,info,flags);
1343 }
1344
1348 void send(const DatagramPacketBase& packet, int flags=0)
1349 {
1350 _impl.send(packet,flags);
1351 }
1352
1356 size_t recv(void* buf, size_t len, int flags=0)
1357 {
1358 return _impl.recv(buf,len,flags);
1359 }
1360
1364 size_t recvfrom(void* buf, size_t len, int flags,
1365 SocketAddress& from)
1366 {
1367 return _impl.recvfrom(buf,len,flags,from);
1368 }
1369
1373 size_t send(const void* buf, size_t len, int flags = 0)
1374 {
1375 return _impl.send(buf,len,flags);
1376 }
1377
1381 size_t send(const struct iovec* iov, int iovcnt, int flags=MSG_NOSIGNAL)
1382 {
1383 return _impl.send(iov,iovcnt,flags);
1384 }
1385
1389 size_t sendto(const void* buf, size_t len, int flags,
1390 const SocketAddress& to)
1391 {
1392 return _impl.sendto(buf,len,flags,to);
1393 }
1394
1398 size_t sendto(const struct iovec* iov, int iovcnt, int flags,
1399 const SocketAddress& to)
1400 {
1401 return _impl.sendto(iov,iovcnt,flags,to);
1402 }
1403
1410 {
1412 }
1413
1419 int getLocalPort() const {
1420 return _impl.getLocalPort();
1421 }
1422
1430 void setNonBlocking(bool val)
1431 {
1432 _impl.setNonBlocking(val);
1433 }
1434
1438 bool isNonBlocking() const
1439 {
1440 return _impl.isNonBlocking();
1441 }
1442
1447 {
1449 }
1450
1455 {
1456 return _impl.getReceiveBufferSize();
1457 }
1458
1462 void setSendBufferSize(int size)
1463 {
1465 }
1466
1471 {
1472 return _impl.getSendBufferSize();
1473 }
1474
1478 std::list<Inet4NetworkInterface> getInterfaces() const
1479 {
1480 return _impl.getInterfaces();
1481 }
1482
1486 void setBroadcastEnable(bool val)
1487 {
1489 }
1490
1495 {
1496 return _impl.getBroadcastEnable();
1497 }
1498
1508 void setPktInfo(bool val)
1509 {
1510 _impl.setPktInfo(val);
1511 }
1512
1513protected:
1515};
1516
1583public:
1584
1597 {
1598 // setInterface(Inet4Address(INADDR_ANY),Inet4Address(INADDR_ANY));
1599 }
1600
1607 {
1608 // setInterface(Inet4Address(INADDR_ANY),Inet4Address(INADDR_ANY));
1609 }
1610
1618 {
1619 // setInterface(Inet4Address(INADDR_ANY),Inet4Address(INADDR_ANY));
1620 }
1621
1627 void joinGroup(Inet4Address groupAddr) {
1628 _impl.joinGroup(groupAddr);
1629 }
1630
1634 /*
1635 void joinGroup(Inet4Address groupAddr,Inet4Address iaddr) throw(IOException) {
1636 _impl.joinGroup(groupAddr,iaddr);
1637 }
1638 */
1639
1643 void joinGroup(Inet4Address groupAddr, const Inet4NetworkInterface &iface) {
1644 _impl.joinGroup(groupAddr,iface);
1645 }
1646
1652 void leaveGroup(Inet4Address groupAddr) {
1653 _impl.leaveGroup(groupAddr);
1654 }
1655
1661 void leaveGroup(Inet4Address groupAddr, const Inet4NetworkInterface& iface)
1662 {
1663 _impl.leaveGroup(groupAddr,iface);
1664 }
1665
1669 void setTimeToLive(int val)
1670 {
1671 _impl.setTimeToLive(val);
1672 }
1673
1677 int getTimeToLive() const
1678 {
1679 return _impl.getTimeToLive();
1680 }
1681
1695 void setMulticastLoop(bool val)
1696 {
1697 _impl.setTimeToLive(val);
1698 }
1699
1703 bool getMulticastLoop() const
1704 {
1705 return _impl.getTimeToLive();
1706 }
1707
1723 _impl.setInterface(maddr,iface);
1724 }
1725
1738 _impl.setInterface(iaddr);
1739 }
1740
1745 return _impl.getInterface();
1746 }
1747
1752 {
1753 return _impl.findInterface(iaddr);
1754 }
1755
1761 std::list<Inet4NetworkInterface> getInterfaces() const
1762 {
1763 return _impl.getInterfaces();
1764 }
1765
1766protected:
1767};
1768
1769}} // namespace nidas namespace util
1770
1771#endif
Abstract base class for a UDP datagram.
Definition DatagramPacket.h:39
A socket for sending or receiving datagrams, either unicast, broadcast or multicast.
Definition Socket.h:1178
void setTimeout(int val)
Set the timeout for receive(), recv(), and recvfrom() methods.
Definition Socket.h:1245
bool getBroadcastEnable() const
Definition Socket.h:1494
size_t recv(void *buf, size_t len, int flags=0)
Definition Socket.h:1356
int getLocalPort() const
Get local port number of this socket.
Definition Socket.h:1419
void setSendBufferSize(int size)
Definition Socket.h:1462
void setBroadcastEnable(bool val)
Definition Socket.h:1486
size_t recvfrom(void *buf, size_t len, int flags, SocketAddress &from)
Definition Socket.h:1364
virtual ~DatagramSocket()
MulticastSocket is derived from DatagramSocket, so we provide a virtual destructor.
Definition Socket.h:1226
void close()
Definition Socket.h:1233
bool isNonBlocking() const
Definition Socket.h:1438
void setReceiveBufferSize(int size)
Definition Socket.h:1446
void bind(const Inet4Address &addr, int port)
Bind the DatagramSocket to the specified local address.
Definition Socket.h:1294
int getReceiveBufferSize()
Definition Socket.h:1454
void connect(const std::string &host, int port)
Datagrams are connectionless, so this doesn't establish a true connection, it just sets the default d...
Definition Socket.h:1257
void connect(const Inet4Address &addr, int port)
Datagrams are connectionless, so this doesn't establish a true connection, it just sets the default d...
Definition Socket.h:1269
void receive(DatagramPacketBase &packet)
Read a packet from the DatagramSocket.
Definition Socket.h:1323
void connect(const SocketAddress &addr)
Datagrams are connectionless, so this doesn't establish a true connection, it just sets the default d...
Definition Socket.h:1281
void bind(const SocketAddress &addr)
Bind the DatagramSocket to the specified local address.
Definition Socket.h:1307
int getSendBufferSize()
Definition Socket.h:1470
size_t sendto(const void *buf, size_t len, int flags, const SocketAddress &to)
Definition Socket.h:1389
void setPktInfo(bool val)
Control whether a IP_PKTINFO ancillary message is received with each datagram.
Definition Socket.h:1508
SocketImpl _impl
Definition Socket.h:1514
std::list< Inet4NetworkInterface > getInterfaces() const
Definition Socket.h:1478
int getFd() const
Definition Socket.h:1312
size_t sendto(const struct iovec *iov, int iovcnt, int flags, const SocketAddress &to)
Definition Socket.h:1398
void setNonBlocking(bool val)
Do fcntl system call to set O_NONBLOCK file descriptor flag on the socket.
Definition Socket.h:1430
size_t send(const struct iovec *iov, int iovcnt, int flags=MSG_NOSIGNAL)
Definition Socket.h:1381
void receive(DatagramPacketBase &packet, Inet4PacketInfo &info, int flags=0)
Read a packet from the DatagramSocket.
Definition Socket.h:1340
size_t send(const void *buf, size_t len, int flags=0)
Definition Socket.h:1373
DatagramSocket()
Create a DatagramSocket not bound to a port.
Definition Socket.cc:1554
void send(const DatagramPacketBase &packet, int flags=0)
Definition Socket.h:1348
const SocketAddress & getLocalSocketAddress() const
Get local address of this socket.
Definition Socket.h:1409
Support for IP version 4 host address.
Definition Inet4Address.h:46
Definition Inet4NetworkInterface.h:36
Ancillary information that can be determined about an incoming UDP packet.
Definition Inet4PacketInfo.h:40
A IP version 4 socket address, containing a host address, and a port number.
Definition Inet4SocketAddress.h:41
A datagram socket to be used for multicasts.
Definition Socket.h:1582
MulticastSocket(int port)
Create multicast socket, bind it to a local port.
Definition Socket.h:1606
MulticastSocket(const Inet4SocketAddress &addr)
Creates a datagram socket and binds it to the specified local address.
Definition Socket.h:1617
int getTimeToLive() const
Definition Socket.h:1677
MulticastSocket()
Create an unbound multicast socket.
Definition Socket.h:1596
Inet4NetworkInterface getInterface() const
Definition Socket.h:1744
void setInterface(Inet4Address maddr, const Inet4NetworkInterface &iface)
Set the interface for a given multicast address.
Definition Socket.h:1722
void joinGroup(Inet4Address groupAddr)
Join a multicast group on all interfaces.
Definition Socket.h:1627
void leaveGroup(Inet4Address groupAddr)
Leave a multicast group on all interfaces.
Definition Socket.h:1652
void setInterface(Inet4Address iaddr)
Set the interface for a given multicast address.
Definition Socket.h:1737
bool getMulticastLoop() const
Definition Socket.h:1703
Inet4NetworkInterface findInterface(const Inet4Address &iaddr) const
Definition Socket.h:1751
void leaveGroup(Inet4Address groupAddr, const Inet4NetworkInterface &iface)
Leave a multicast group on a given interface.
Definition Socket.h:1661
void setMulticastLoop(bool val)
Whether to set the IP_MULTICAST_LOOP socket option.
Definition Socket.h:1695
void setTimeToLive(int val)
Definition Socket.h:1669
void joinGroup(Inet4Address groupAddr, const Inet4NetworkInterface &iface)
Join a multicast group on a given interface.
Definition Socket.h:1643
std::list< Inet4NetworkInterface > getInterfaces() const
Return the IP addresses of all my network interfaces.
Definition Socket.h:1761
A stream (TCP) socket that is used to listen for connections.
Definition Socket.h:981
void close()
Close the socket.
Definition Socket.cc:1537
int getSendBufferSize()
Definition Socket.h:1077
void setSendBufferSize(int size)
Definition Socket.h:1069
void setNonBlocking(bool val)
Definition Socket.h:1106
bool isNonBlocking() const
Definition Socket.h:1114
ServerSocket(int port=0, int backlog=10)
Create a AF_INET ServerSocket bound to a port on all local interfaces.
Definition Socket.cc:1489
SocketImpl _impl
Definition Socket.h:1120
int getReceiveBufferSize()
Definition Socket.h:1061
void setReceiveBufferSize(int size)
Definition Socket.h:1053
~ServerSocket()
Destructor.
Definition Socket.h:1016
int getFd() const
Definition Socket.h:1019
const SocketAddress & getLocalSocketAddress() const
Fetch the local address that this socket is bound to.
Definition Socket.h:1087
int getLocalPort() const
Definition Socket.h:1095
int getDomain() const
Definition Socket.h:1099
Socket * accept()
Accept connection, return a connected Socket instance.
Definition Socket.h:1045
An interface for a socket address.
Definition SocketAddress.h:36
virtual int getPort() const =0
return the port number of this address, or -1 if there is no associated port number,...
Implementation of a socket, providing a C++ interface to system socket calls: socket,...
Definition Socket.h:76
void getLocalAddr()
Do system call to determine local address of this socket.
Definition Socket.cc:378
void setReuseAddress(bool val)
Definition Socket.h:151
void setNonBlocking(bool val)
Definition Socket.cc:426
bool isNonBlocking() const
Definition Socket.cc:451
void setKeepAliveIdleSecs(int val)
Set the number of seconds a connection needs to be idle before TCP begins sending out keep-alive prob...
Definition Socket.cc:994
size_t sendto(const void *buf, size_t len, int flags, const SocketAddress &to)
Definition Socket.cc:858
void setSendBufferSize(int size)
Definition Socket.cc:926
void leaveGroup(Inet4Address groupAddr)
Leave a multicast group on all interfaces.
Definition Socket.cc:1138
void setReceiveBufferSize(int size)
Definition Socket.cc:906
int getDomain() const
Get the domain of this socket: AF_UNIX, AF_INET, etc, from sys/socket.h.
Definition Socket.h:107
SocketImpl(int domain, int type)
Definition Socket.cc:62
bool getMulticastLoop() const
Definition Socket.cc:1305
void setMulticastLoop(bool val)
Whether to set the IP_MULTICAST_LOOP socket option.
Definition Socket.cc:1294
const SocketAddress & getLocalSocketAddress() const
Get local socket address of this socket.
Definition Socket.h:116
void setInterface(Inet4Address maddr, const Inet4NetworkInterface &iaddr)
Definition Socket.cc:1168
SocketAddress * _remoteaddr
Definition Socket.h:525
bool getTcpNoDelay()
Get the TCP_NODELAY (man 7 tcp) option on the socket.
Definition Socket.cc:958
int getTimeToLive() const
Definition Socket.cc:1281
struct timespec _timeout
Definition Socket.h:530
bool _pktInfo
Definition Socket.h:532
int getKeepAliveIdleSecs() const
Get the current value of TCP_KEEPIDLE on this socket.
Definition Socket.cc:1018
SocketImpl & operator=(const SocketImpl &rhs)
Assignment operator.
Definition Socket.cc:98
void setBroadcastEnable(bool val)
Enable or disable SO_BROADCAST.
Definition Socket.cc:1318
Socket * accept()
Definition Socket.cc:232
SocketAddress * _localaddr
Definition Socket.h:524
void setBacklog(int val)
Definition Socket.h:109
int getTimeout() const
Definition Socket.cc:129
int getOutQueueSize() const
Get number of bytes currently unsent in the local output queue.
Definition Socket.cc:1043
void setPktInfo(bool val)
Control whether a IP_PKTINFO ancillary message is received with each datagram.
Definition Socket.cc:1429
const SocketAddress & getRemoteSocketAddress() const
Get remote socket address of this socket.
Definition Socket.h:136
void connect(const std::string &dest, int port)
Definition Socket.cc:145
bool getPktInfo() const
Definition Socket.h:453
~SocketImpl()
Definition Socket.cc:116
void bind(int port)
Definition Socket.cc:175
int getLocalPort() const
Get local port number of this socket.
Definition Socket.h:126
void joinGroup(Inet4Address groupAddr)
Join a multicast group on all interfaces.
Definition Socket.cc:1057
void getRemoteAddr()
Do system call to determine address of remote end.
Definition Socket.cc:402
int _fd
Definition Socket.h:526
void setTimeToLive(int val)
Definition Socket.cc:1271
Inet4NetworkInterface getInterface() const
Definition Socket.cc:1222
int getReceiveBufferSize()
Definition Socket.cc:914
void receive(DatagramPacketBase &packet)
Definition Socket.cc:462
int _sockdomain
Definition Socket.h:522
void setTimeout(int val)
Set the timeout for receive(), recv(), and recvfrom() methods.
Definition Socket.cc:122
bool _hasTimeout
Definition Socket.h:529
bool getKeepAlive() const
Get the current value of the SO_KEEPALIVE socket option.
Definition Socket.cc:982
int _socktype
Definition Socket.h:523
void close()
Definition Socket.cc:134
std::list< Inet4NetworkInterface > getInterfaces() const
Definition Socket.cc:1382
int _backlog
Definition Socket.h:527
int getFd() const
Definition Socket.h:101
Inet4NetworkInterface findInterface(const Inet4Address &) const
Definition Socket.cc:1202
void sendall(const void *buf, size_t len, int flags=0)
send all data in buffer on socket, repeating send() as necessary, until all data is sent (or an excep...
Definition Socket.cc:889
bool getBroadcastEnable() const
Definition Socket.cc:1329
bool _reuseaddr
Definition Socket.h:528
int getRemotePort() const
Get remote port number of this socket.
Definition Socket.h:146
void setTcpNoDelay(bool val)
Set the TCP_NODELAY (man 7 tcp) option on the socket.
Definition Socket.cc:946
size_t recvfrom(void *buf, size_t len, int flags, SocketAddress &from)
Definition Socket.cc:746
void setKeepAlive(bool val)
Set or unset the SO_KEEPALIVE socket option.
Definition Socket.cc:970
size_t recv(void *buf, size_t len, int flags=0)
Receive data on a socket.
Definition Socket.cc:679
void send(const DatagramPacketBase &packet, int flags=0)
Definition Socket.cc:817
void listen()
Definition Socket.cc:222
int getInQueueSize() const
Get number of bytes currently unread in the local input queue.
Definition Socket.cc:1031
int getSendBufferSize()
Definition Socket.cc:934
A stream (TCP) socket.
Definition Socket.h:573
static std::vector< Socket * > createSocketPair(int type=SOCK_STREAM)
Create a pair of connnected unix sockets.
Definition Socket.cc:1596
int getSendBufferSize()
Definition Socket.h:883
void close()
Definition Socket.h:629
void setNonBlocking(bool val)
Do fcntl system call to set O_NONBLOCK file descriptor flag on the socket.
Definition Socket.h:658
void connect(const std::string &host, int port)
Connect to a given remote host and port.
Definition Socket.h:777
int getKeepAliveIdleSecs()
Get the current value of TCP_KEEPIDLE on this socket.
Definition Socket.h:740
int getLocalPort() const
Get local port number of this socket.
Definition Socket.h:922
~Socket()
Definition Socket.h:623
bool getKeepAlive()
Get the current value of the SO_KEEPALIVE socket option.
Definition Socket.h:702
void setKeepAlive(bool val)
Set or unset the SO_KEEPALIVE socket option.
Definition Socket.h:692
void setSendBufferSize(int size)
Definition Socket.h:875
Socket(int domain=AF_INET)
Create an unconnected stream socket.
Definition Socket.cc:1441
int getInQueueSize() const
Definition Socket.h:748
size_t recv(void *buf, size_t len, int flags=0)
Definition Socket.h:813
void setTcpNoDelay(bool val)
Definition Socket.h:674
void connect(const SocketAddress &addr)
Connect to a given remote socket address.
Definition Socket.h:797
SocketImpl _impl
Definition Socket.h:932
void setReceiveBufferSize(int size)
Definition Socket.h:859
int getRemotePort() const
Get remote port number of this socket.
Definition Socket.h:903
std::list< Inet4NetworkInterface > getInterfaces() const
Get a list of all my network interfaces.
Definition Socket.h:766
int getFd() const
Fetch the file descriptor associate with this socket.
Definition Socket.h:805
int getReceiveBufferSize()
Definition Socket.h:867
const SocketAddress & getRemoteSocketAddress() const
Get remote address of this socket.
Definition Socket.h:893
void sendall(const void *buf, size_t len, int flags=MSG_NOSIGNAL)
send all data in buffer on socket, repeating send() as necessary, until all data is sent (or an excep...
Definition Socket.h:851
int getDomain() const
Definition Socket.h:926
void connect(const Inet4Address &addr, int port)
Connect to a given remote host address and port.
Definition Socket.h:787
int getOutQueueSize() const
Definition Socket.h:756
size_t send(const struct iovec *iov, int iovcnt, int flags=MSG_NOSIGNAL)
Definition Socket.h:834
const SocketAddress & getLocalSocketAddress() const
Get local address of this socket.
Definition Socket.h:912
void setKeepAliveIdleSecs(int val)
Set the number of seconds a connection needs to be idle before TCP begins sending out keep-alive prob...
Definition Socket.h:728
bool getTcpNoDelay()
Definition Socket.h:682
void setTimeout(int val)
Set the timeout for receive(), recv(), and recvfrom() methods.
Definition Socket.h:649
bool isNonBlocking() const
Definition Socket.h:666
size_t send(const void *buf, size_t len, int flags=MSG_NOSIGNAL)
send data on socket, see man page for send system function.
Definition Socket.h:826
Root namespace for the NCAR In-Situ Data Acquisition Software.
Definition A2DConverter.h:31
static n_u::SerialPort port
Definition sing.cc:68
int len
Definition sing.cc:948
int fd
Definition twod.c:56