SDRAngel
4.11.5
Developer docs for <a href="https://github.com/f4exb/sdrangel">SDRangel<\a>, an Open Source Qt5 / OpenGL 3.0+ SDR and signal analyzer frontend to various hardware.
|
#include <UDPSocket.h>
Public Types | |
enum | SocketType { TcpSocket = SOCK_STREAM, UdpSocket = SOCK_DGRAM, UnknownSocketType =-1 } |
enum | NetworkLayerProtocol { IPv4Protocol = AF_INET, IPv6Protocol = AF_INET6, UnknownNetworkLayerProtocol = -1 } |
enum | ReadResult { DATA_ARRIVED = 0, DATA_TIMED_OUT = ETIMEDOUT, DATA_EXCEPTION = 255 } |
Public Member Functions | |
virtual | ~CSocket () |
string | GetLocalAddress () |
unsigned short | GetLocalPort () |
void | BindLocalPort (unsigned short localPort) |
void | BindLocalAddressAndPort (const string &localAddress, unsigned short localPort=0) |
unsigned long int | GetReadBufferSize () |
void | SetReadBufferSize (unsigned int nSize) |
void | SetNonBlocking (bool bBlocking) |
void | ConnectToHost (const string &foreignAddress, unsigned short foreignPort) |
void | Send (const void *buffer, int bufferLen) |
int | Recv (void *buffer, int bufferLen) |
string | GetPeerAddress () |
unsigned short | GetPeerPort () |
CSocket & | operator<< (const string &sStr) |
CSocket & | operator>> (string &sStr) |
virtual int | OnDataRead (unsigned long timeToWait=ULONG_MAX) |
void | SetBindToDevice (const string &sInterface) |
Protected Member Functions | |
CSocket (SocketType type, NetworkLayerProtocol protocol) | |
CSocket (int sockDesc) | |
Static Protected Member Functions | |
static void | FillAddr (const string &localAddress, unsigned short localPort, sockaddr_in &localAddr) |
Protected Attributes | |
int | m_sockDesc |
Private Member Functions | |
CSocket (const CSocket &sock) | |
void | operator= (const CSocket &sock) |
Base class representing basic communication endpoint.
Definition at line 77 of file UDPSocket.h.
Enum to represent type network layer protocol used for socket
Enumerator | |
---|---|
IPv4Protocol | |
IPv6Protocol | |
UnknownNetworkLayerProtocol |
Definition at line 95 of file UDPSocket.h.
enum CSocket::ReadResult |
Enum to represent Wait Result when reading data from a socket
Enumerator | |
---|---|
DATA_ARRIVED | |
DATA_TIMED_OUT | |
DATA_EXCEPTION |
Definition at line 105 of file UDPSocket.h.
enum CSocket::SocketType |
Enum to represent type of socket(UDP or TCP)
Enumerator | |
---|---|
TcpSocket | |
UdpSocket | |
UnknownSocketType |
Definition at line 85 of file UDPSocket.h.
|
virtual |
Definition at line 47 of file UDPSocket.cpp.
|
protected |
|
protected |
Definition at line 62 of file UDPSocket.cpp.
References m_sockDesc.
|
private |
void CSocket::BindLocalAddressAndPort | ( | const string & | localAddress, |
unsigned short | localPort = 0 |
||
) |
Set the local port to the specified port and the local address to the specified address. If you omit the port, a random port will be selected.
localAddress | local address |
localPort | local port |
CSocketException | thrown if setting local port or address fails |
Definition at line 113 of file UDPSocket.cpp.
References FillAddr(), and m_sockDesc.
Referenced by UDPSocket::UDPSocket().
void CSocket::BindLocalPort | ( | unsigned short | localPort | ) |
Set the local port to the specified port and the local address to any interface
localPort | local port |
CSocketException | thrown if setting local port fails |
Definition at line 99 of file UDPSocket.cpp.
References m_sockDesc.
Referenced by UDPSocket::UDPSocket().
void CSocket::ConnectToHost | ( | const string & | foreignAddress, |
unsigned short | foreignPort | ||
) |
Establish a socket connection with the given foreign address and port
foreignAddress | foreign address (IP address or name) |
foreignPort | foreign port |
SocketException | thrown if unable to establish connection |
Definition at line 176 of file UDPSocket.cpp.
References FillAddr(), and m_sockDesc.
|
staticprotected |
Definition at line 124 of file UDPSocket.cpp.
Referenced by BindLocalAddressAndPort(), ConnectToHost(), and UDPSocket::SendDataGram().
std::string CSocket::GetLocalAddress | ( | ) |
Get the local address
CSocketException | thrown if fetch fails |
Definition at line 77 of file UDPSocket.cpp.
References m_sockDesc.
unsigned short CSocket::GetLocalPort | ( | ) |
Get the local port
CSocketException | thrown if fetch fails |
Definition at line 88 of file UDPSocket.cpp.
References m_sockDesc.
std::string CSocket::GetPeerAddress | ( | ) |
Get the foreign address. Call connect() before calling recv()
SocketException | thrown if unable to fetch foreign address |
Definition at line 206 of file UDPSocket.cpp.
References m_sockDesc.
unsigned short CSocket::GetPeerPort | ( | ) |
Get the foreign port. Call connect() before calling recv()
SocketException | thrown if unable to fetch foreign port |
Definition at line 217 of file UDPSocket.cpp.
References m_sockDesc.
unsigned long int CSocket::GetReadBufferSize | ( | ) |
Returns the size of the internal read buffer. This limits the amount of data that the client can receive before you call
Definition at line 140 of file UDPSocket.cpp.
References m_sockDesc.
Referenced by operator>>().
|
virtual |
Blocking function to check whether data arrived in socket for reading.
timeToWait | waits for 'timeToWait' seconds. |
Definition at line 243 of file UDPSocket.cpp.
References DATA_ARRIVED, DATA_EXCEPTION, DATA_TIMED_OUT, and m_sockDesc.
CSocket & CSocket::operator<< | ( | const string & | sStr | ) |
Writing sStr to socket
Definition at line 228 of file UDPSocket.cpp.
References Send().
|
private |
CSocket & CSocket::operator>> | ( | string & | sStr | ) |
Reading data to sStr from socket
Definition at line 234 of file UDPSocket.cpp.
References GetReadBufferSize(), and Recv().
int CSocket::Recv | ( | void * | buffer, |
int | bufferLen | ||
) |
Read into the given buffer up to bufferLen bytes data from this socket. Call connect() before calling recv()
buffer | buffer to receive the data |
bufferLen | maximum number of bytes to read into buffer |
SocketException | thrown if unable to receive data |
Definition at line 195 of file UDPSocket.cpp.
References m_sockDesc.
Referenced by operator>>().
void CSocket::Send | ( | const void * | buffer, |
int | bufferLen | ||
) |
Write the given buffer to this socket. Call connect() before calling send()
buffer | buffer to be written |
bufferLen | number of bytes from buffer to be written |
SocketException | thrown if unable to send data |
Definition at line 188 of file UDPSocket.cpp.
References m_sockDesc.
Referenced by operator<<().
void CSocket::SetBindToDevice | ( | const string & | sInterface | ) |
To Bind socket to a symbolic device name like eth0
sInterface | NIC device name |
Definition at line 292 of file UDPSocket.cpp.
void CSocket::SetNonBlocking | ( | bool | bBlocking | ) |
Sets the socket to Blocking/Non blocking state.
Bool | flag for Non blocking status. |
Definition at line 157 of file UDPSocket.cpp.
References m_sockDesc.
void CSocket::SetReadBufferSize | ( | unsigned int | nSize | ) |
Sets the read buffer size of the socket.
Size | of the buffer. |
Definition at line 149 of file UDPSocket.cpp.
References m_sockDesc.
|
protected |
Internal Socket descriptor
Definition at line 235 of file UDPSocket.h.
Referenced by BindLocalAddressAndPort(), BindLocalPort(), ConnectToHost(), CSocket(), UDPSocket::DisconnectFromHost(), GetLocalAddress(), GetLocalPort(), GetPeerAddress(), GetPeerPort(), GetReadBufferSize(), UDPSocket::JoinGroup(), UDPSocket::LeaveGroup(), OnDataRead(), operator=(), Recv(), UDPSocket::RecvDataGram(), Send(), UDPSocket::SendDataGram(), UDPSocket::SetBroadcast(), UDPSocket::SetMulticastTTL(), SetNonBlocking(), and SetReadBufferSize().