![]() |
YDLIDAR SDK
V1.3.6
|
#include <SimpleSocket.h>
Public Types | |
enum | CShutdownMode { Receives = SHUT_RD, Sends = SHUT_WR, Both = SHUT_RDWR } |
Defines the three possible states for shuting down a socket. More... | |
enum | CSocketType { SocketTypeInvalid = 0, SocketTypeTcp, SocketTypeUdp, SocketTypeTcp6, SocketTypeUdp6, SocketTypeRaw } |
Defines the socket types defined by CSimpleSocket class. More... | |
enum | CSocketError { SocketError = -1, SocketSuccess = 0, SocketInvalidSocket, SocketInvalidAddress, SocketInvalidPort, SocketConnectionRefused, SocketTimedout, SocketEwouldblock, SocketNotconnected, SocketEinprogress, SocketInterrupted, SocketConnectionAborted, SocketProtocolError, SocketFirewallError, SocketInvalidSocketBuffer, SocketConnectionReset, SocketAddressInUse, SocketInvalidPointer, SocketEunknown } |
Defines all error codes handled by the CSimpleSocket class. More... | |
Public Member Functions | |
CSimpleSocket (CSocketType type=SocketTypeTcp) | |
CSimpleSocket (CSimpleSocket &socket) | |
virtual bool | Initialize (void) |
virtual bool | Close (void) |
virtual bool | Shutdown (CShutdownMode nShutdown) |
virtual bool | Select (void) |
virtual bool | Select (int32_t nTimeoutSec, int32_t nTimeoutUSec) |
virtual int | WaitForData (size_t data_count, uint32_t timeout, size_t *returned_size) |
virtual bool | IsSocketValid (void) |
void | TranslateSocketError (void) |
const char * | DescribeError () |
virtual int32_t | Receive (int32_t nMaxBytes=1, uint8_t *pBuffer=0) |
virtual int32_t | Send (const uint8_t *pBuf, size_t bytesToSend) |
virtual int32_t | Send (const struct iovec *sendVector, int32_t nNumItems) |
virtual int32_t | SendFile (int32_t nOutFd, int32_t nInFd, off_t *pOffset, int32_t nCount) |
bool | IsNonblocking (void) |
bool | SetBlocking (void) |
bool | SetNonblocking (void) |
uint8_t * | GetData (void) |
int32_t | GetBytesReceived (void) |
int32_t | GetBytesSent (void) |
bool | SetOptionLinger (bool bEnable, uint16_t nTime) |
bool | SetOptionReuseAddr () |
int32_t | GetConnectTimeoutSec (void) |
int32_t | GetConnectTimeoutUSec (void) |
void | SetConnectTimeout (int32_t nConnectTimeoutSec, int32_t nConnectTimeoutUsec=0) |
int32_t | GetReceiveTimeoutSec (void) |
int32_t | GetReceiveTimeoutUSec (void) |
bool | SetReceiveTimeout (int32_t nRecvTimeoutSec, int32_t nRecvTimeoutUsec=0) |
bool | SetMulticast (bool bEnable, uint8_t multicastTTL=1) |
bool | GetMulticast () |
bool | BindInterface (const char *pInterface) |
int32_t | GetSendTimeoutSec (void) |
int32_t | GetSendTimeoutUSec (void) |
bool | SetSendTimeout (int32_t nSendTimeoutSec, int32_t nSendTimeoutUsec=0) |
CSocketError | GetSocketError (void) |
uint32_t | GetTotalTimeMs () |
uint32_t | GetTotalTimeUsec () |
int | GetSocketDscp (void) |
bool | SetSocketDscp (int nDscp) |
SOCKET | GetSocketDescriptor () |
CSocketType | GetSocketType () |
void | SetSocketType (const CSocketType &type) |
set socket descriptor | |
const char * | GetClientAddr () |
uint16_t | GetClientPort () |
const char * | GetServerAddr () |
uint16_t | GetServerPort () |
uint32_t | GetReceiveWindowSize () |
uint32_t | GetSendWindowSize () |
uint32_t | SetReceiveWindowSize (uint32_t nWindowSize) |
uint32_t | SetSendWindowSize (uint32_t nWindowSize) |
bool | DisableNagleAlgoritm () |
bool | EnableNagleAlgoritm () |
virtual bool | Open (const char *pAddr, uint16_t nPort) |
virtual bool | bindport (const char *, uint32_t) |
virtual bool | open () |
virtual bool | isOpen () |
virtual void | closePort () |
virtual void | flush () |
virtual int | waitfordata (size_t data_count, uint32_t timeout=-1, size_t *returned_size=NULL) |
virtual size_t | writeData (const uint8_t *data, size_t size) |
virtual size_t | readData (uint8_t *data, size_t size) |
![]() | |
virtual bool | setDTR (bool level=true) |
virtual int | getByteTime () |
virtual void | ReleasePort () |
Static Public Member Functions | |
static const char * | DescribeError (CSocketError err) |
Protected Member Functions | |
void | SetSocketError (CSimpleSocket::CSocketError error) |
void | SetSocketHandle (SOCKET socket) |
bool | Flush () |
Protected Attributes | |
SOCKET | m_socket |
CSocketError | m_socketErrno |
socket handle | |
uint8_t * | m_pBuffer |
number of last error | |
int32_t | m_nBufferSize |
internal send/receive buffer | |
int32_t | m_nSocketDomain |
size of internal send/receive buffer | |
CSocketType | m_nSocketType |
socket type PF_INET, PF_INET6 | |
int32_t | m_nBytesReceived |
socket type - UDP, TCP or RAW | |
int32_t | m_nBytesSent |
number of bytes received | |
uint32_t | m_nFlags |
number of bytes sent | |
bool | m_bIsBlocking |
socket flags | |
bool | m_bIsMulticast |
is socket blocking | |
struct timeval | m_stConnectTimeout |
is the UDP socket multicast; | |
struct timeval | m_stRecvTimeout |
connection timeout | |
struct timeval | m_stSendTimeout |
receive timeout | |
struct sockaddr_in | m_stServerSockaddr |
send timeout | |
struct sockaddr_in | m_stClientSockaddr |
server address | |
struct sockaddr_in | m_stMulticastGroup |
client address | |
struct linger | m_stLinger |
multicast group to bind to | |
CStatTimer | m_timer |
linger flag | |
fd_set | m_writeFds |
internal statistics. | |
fd_set | m_readFds |
write file descriptor set | |
fd_set | m_errorFds |
read file descriptor set | |
std::string | m_addr |
error file descriptor set | |
uint32_t | m_port |
bool | m_open |
Provides a platform independent class to for socket development. This class is designed to abstract socket communication development in a platform independent manner.
Defines all error codes handled by the CSimpleSocket class.
Enumerator | |
---|---|
SocketError |
Generic socket error translates to error below. |
SocketSuccess |
No socket error. |
SocketInvalidSocket |
Invalid socket handle. |
SocketInvalidAddress |
Invalid destination address specified. |
SocketInvalidPort |
Invalid destination port specified. |
SocketConnectionRefused |
No server is listening at remote address. |
SocketTimedout |
Timed out while attempting operation. |
SocketEwouldblock |
Operation would block if socket were blocking. |
SocketNotconnected |
Currently not connected. |
SocketEinprogress |
Socket is non-blocking and the connection cannot be completed immediately. |
SocketInterrupted |
Call was interrupted by a signal that was caught before a valid connection arrived. |
SocketConnectionAborted |
The connection has been aborted. |
SocketProtocolError |
Invalid protocol for operation. |
SocketFirewallError |
Firewall rules forbid connection. |
SocketInvalidSocketBuffer |
The receive buffer point outside the process's address space. |
SocketConnectionReset |
Connection was forcibly closed by the remote host. |
SocketAddressInUse |
Address already in use. |
SocketInvalidPointer |
Pointer type supplied as argument is invalid. |
SocketEunknown |
Unknown error please report to mark@. carr ierla bs.c om |
Defines the socket types defined by CSimpleSocket class.
bool CSimpleSocket::BindInterface | ( | const char * | pInterface | ) |
Bind socket to a specific interface when using multicast.
|
virtual |
Close socket
|
static |
Returns a human-readable description of the given error code or the last error code of a socket
bool CSimpleSocket::DisableNagleAlgoritm | ( | ) |
Disable the Nagle algorithm (Set TCP_NODELAY to true)
bool CSimpleSocket::EnableNagleAlgoritm | ( | ) |
Enable the Nagle algorithm (Set TCP_NODELAY to false)
|
protected |
Flush the socket descriptor owned by the object.
|
inline |
Returns the number of bytes received on the last call to CSocket::Receive().
|
inline |
Returns the number of bytes sent on the last call to CSocket::Send().
|
inline |
Returns clients Internet host address as a string in standard numbers-and-dots notation.
|
inline |
Returns the port number on which the client is connected.
|
inline |
Gets the timeout value that specifies the maximum number of seconds a call to CSimpleSocket::Open waits until it completes.
|
inline |
Gets the timeout value that specifies the maximum number of microseconds a call to CSimpleSocket::Open waits until it completes.
|
inline |
Get a pointer to internal receive buffer. The user MUST not free this pointer when finished. This memory is managed internally by the CSocket class.
|
inline |
Return true if socket is multicast or false is socket is unicast
|
inline |
Gets the timeout value that specifies the maximum number of seconds a a call to CSimpleSocket::Receive waits until it completes.
|
inline |
Gets the timeout value that specifies the maximum number of microseconds a call to CSimpleSocket::Receive waits until it completes.
|
inline |
Get the TCP receive buffer window size for the current socket object.
NOTE: Linux will set the receive buffer to twice the value passed.
|
inline |
Gets the timeout value that specifies the maximum number of seconds a a call to CSimpleSocket::Send waits until it completes.
|
inline |
Gets the timeout value that specifies the maximum number of microseconds a call to CSimpleSocket::Send waits until it completes.
|
inline |
Get the TCP send buffer window size for the current socket object.
NOTE: Linux will set the send buffer to twice the value passed.
|
inline |
Returns server Internet host address as a string in standard numbers-and-dots notation.
|
inline |
Returns the port number on which the server is connected.
|
inline |
Return socket descriptor
int32_t CSimpleSocket::GetSocketDscp | ( | void | ) |
Return Differentiated Services Code Point (DSCP) value currently set on the socket object.
|
inline |
Returns the last error that occured for the instace of the CSimpleSocket instance. This method should be called immediately to retrieve the error code for the failing mehtod call.
|
inline |
Return socket descriptor
|
inline |
Get the total time the of the last operation in milliseconds.
|
inline |
Get the total time the of the last operation in microseconds.
|
virtual |
Initialize instance of CSocket. This method MUST be called before an object can be used. Errors : CSocket::SocketProtocolError, CSocket::SocketInvalidSocket,
|
inline |
Returns blocking/non-blocking state of socket.
|
inlinevirtual |
Does the current instance of the socket object contain a valid socket descriptor.
|
virtual |
Attempts to receive a block of data on an established connection.
nMaxBytes | maximum number of bytes to receive. |
pBuffer,memory | where to receive the data, NULL receives to internal buffer returned with GetData() Non-NULL receives directly there, but GetData() will return WRONG ptr! |
|
inlinevirtual |
Examine the socket descriptor sets currently owned by the instance of the socket class (the readfds, writefds, and errorfds parameters) to see whether some of their descriptors are ready for reading, are ready for writing, or have an exceptional condition pending, respectively. Block until an event happens on the specified file descriptors.
|
virtual |
Examine the socket descriptor sets currently owned by the instance of the socket class (the readfds, writefds, and errorfds parameters) to see whether some of their descriptors are ready for reading, are ready for writing, or have an exceptional condition pending, respectively.
nTimeoutSec | timeout in seconds for select. |
nTimeoutUSec | timeout in micro seconds for select. |
|
virtual |
Attempts to send a block of data on an established connection.
pBuf | block of data to be sent. |
bytesToSend | size of data block to be sent. |
Reimplemented in ydlidar::CPassiveSocket.
|
virtual |
Attempts to send at most nNumItem blocks described by sendVector to the socket descriptor associated with the socket object.
sendVector | pointer to an array of iovec structures |
nNumItems | number of items in the vector to process NOTE: Buffers are processed in the order specified. |
|
virtual |
Copies data between one file descriptor and another. On some systems this copying is done within the kernel, and thus is more efficient than the combination of CSimpleSocket::Send and CSimpleSocket::Receive, which would require transferring data to and from user space.
Note: This is available on all implementations, but the kernel implementation is only available on Unix type systems.
nOutFd | descriptor opened for writing. |
nInFd | descriptor opened for reading. |
pOffset | from which to start reading data from input file. |
nCount | number of bytes to copy between file descriptors. |
bool CSimpleSocket::SetBlocking | ( | void | ) |
Set the socket to blocking.
|
inline |
Sets the timeout value that specifies the maximum amount of time a call to CSimpleSocket::Receive waits until it completes. Use the method CSimpleSocket::SetReceiveTimeout to specify the number of seconds to wait. If a call to CSimpleSocket::Receive has blocked for the specified length of time without receiving additional data, it returns with a partial count or CSimpleSocket::GetSocketError set to CSimpleSocket::SocketEwouldblock if no data were received.
nConnectTimeoutSec | of timeout in seconds. |
nConnectTimeoutUsec | of timeout in microseconds. |
bool CSimpleSocket::SetMulticast | ( | bool | bEnable, |
uint8_t | multicastTTL = 1 |
||
) |
Enable/disable multicast for a socket. This options is only valid for socket descriptors of type CSimpleSocket::SocketTypeUdp.
bool CSimpleSocket::SetNonblocking | ( | void | ) |
Set the socket as non-blocking.
bool CSimpleSocket::SetOptionLinger | ( | bool | bEnable, |
uint16_t | nTime | ||
) |
Controls the actions taken when CSimpleSocket::Close is executed on a socket object that has unsent data. The default value for this option is off.
Following are the three possible scenarios.
bEnable | true to enable option false to disable option. |
nTime | time in seconds to linger. |
bool CSimpleSocket::SetOptionReuseAddr | ( | ) |
Tells the kernel that even if this port is busy (in the TIME_WAIT state), go ahead and reuse it anyway. If it is busy, but with another state, you will still get an address already in use error.
bool CSimpleSocket::SetReceiveTimeout | ( | int32_t | nRecvTimeoutSec, |
int32_t | nRecvTimeoutUsec = 0 |
||
) |
Sets the timeout value that specifies the maximum amount of time a call to CSimpleSocket::Receive waits until it completes. Use the method CSimpleSocket::SetReceiveTimeout to specify the number of seconds to wait. If a call to CSimpleSocket::Receive has blocked for the specified length of time without receiving additional data, it returns with a partial count or CSimpleSocket::GetSocketError set to CSimpleSocket::SocketEwouldblock if no data were received.
nRecvTimeoutSec | of timeout in seconds. |
nRecvTimeoutUsec | of timeout in microseconds. |
|
inline |
Set the TCP receive buffer window size for the current socket object.
NOTE: Linux will set the receive buffer to twice the value passed.
bool CSimpleSocket::SetSendTimeout | ( | int32_t | nSendTimeoutSec, |
int32_t | nSendTimeoutUsec = 0 |
||
) |
Gets the timeout value that specifies the maximum amount of time a call to CSimpleSocket::Send waits until it completes.
|
inline |
Set the TCP send buffer window size for the current socket object.
NOTE: Linux will set the send buffer to twice the value passed.
bool CSimpleSocket::SetSocketDscp | ( | int | nDscp | ) |
Set Differentiated Services Code Point (DSCP) for socket object.
nDscp | value of TOS setting which will be converted to DSCP |
|
inlineprotected |
Set internal socket error to that specified error
error | type of error |
|
inlineprotected |
Set object socket handle to that specified as parameter
socket | value of socket descriptor |
|
virtual |
Shutdown shut down socket send and receive operations CShutdownMode::Receives - Disables further receive operations. CShutdownMode::Sends - Disables further send operations. CShutdownBoth:: - Disables further send and receive operations.
nShutdown | specifies the type of shutdown. |
void CSimpleSocket::TranslateSocketError | ( | void | ) |
Provides a standard error code for cross platform development by mapping the operating system error to an error defined by the CSocket class.