You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
113 lines
2.2 KiB
113 lines
2.2 KiB
#ifndef __SOCKETPORT_H_INCL__
|
|
#define __SOCKETPORT_H_INCL__
|
|
|
|
#include <errno.h> // Error number definitions
|
|
#include <fcntl.h> // File control definitions
|
|
#include <stdio.h> // standard input / output functions
|
|
#include <stdlib.h>
|
|
#include <string.h> // string function definitions
|
|
#ifdef __linux__
|
|
#include <netdb.h>
|
|
#include <netinet/in.h>
|
|
#include <sys/ioctl.h>
|
|
#include <sys/socket.h>
|
|
#include <sys/types.h>
|
|
#include <unistd.h> // UNIX standard function definitions
|
|
#else
|
|
// #include <winsock.h>
|
|
#include <windows.h>
|
|
#include <winsock2.h>
|
|
#include <ws2tcpip.h>
|
|
#endif
|
|
|
|
#include "../transport/transportSocket.h"
|
|
|
|
#define MAX_HOST_STRING_SIZE 128
|
|
|
|
// #define DUBUG_COMMUNICATION
|
|
// #define CLIENT_SOCKET_NON_BLOCKING
|
|
/**
|
|
* TODO: Add class description
|
|
*
|
|
* @author Gagua
|
|
*/
|
|
class clientPort : public transportSocket
|
|
{
|
|
private:
|
|
|
|
basicLogCollection * m_pLog;
|
|
char m_cHostName[MAX_HOST_STRING_SIZE];
|
|
#ifdef __linux__
|
|
int m_nSocketFD;
|
|
#else
|
|
SOCKET m_nSocketFD;
|
|
#endif
|
|
int m_nPort;
|
|
bool m_bKeepAlive;
|
|
bool _connect(void);
|
|
|
|
protected:
|
|
|
|
int sendBlock(unsigned char * Data, int DataSize);
|
|
int recptBlock(unsigned char * Buffer, int * BufferLength);
|
|
|
|
public:
|
|
|
|
// Constructor
|
|
clientPort();
|
|
clientPort(CSTR URI);
|
|
clientPort(CSTR Host, int Port, bool KeepALive = true);
|
|
|
|
// Destructor
|
|
virtual ~clientPort();
|
|
virtual bool create();
|
|
|
|
virtual int getRawHandle(void)
|
|
{
|
|
return m_nSocketFD;
|
|
}
|
|
|
|
bool disconnect(void);
|
|
bool connectTo(CSTR Host, int Port);
|
|
|
|
bool reconnect(void)
|
|
{
|
|
return _connect();
|
|
;
|
|
}
|
|
|
|
bool isConnected(void)
|
|
{
|
|
return getConnectionStatus() == CS_CONNECTED;
|
|
}
|
|
|
|
void setKeepAlive(bool Param);
|
|
|
|
bool getKeepAlive(void)
|
|
{
|
|
return m_bKeepAlive;
|
|
}
|
|
|
|
CSTR getLocalIp4();
|
|
CSTR getRemoteIp4();
|
|
};
|
|
|
|
// TODO: Uncomment the copy constructor when you need it.
|
|
// inline socketPort::socketPort(const socketPort& src)
|
|
//{
|
|
// // TODO: copy
|
|
//}
|
|
|
|
// TODO: Uncomment the assignment operator when you need it.
|
|
// inline socketPort& socketPort::operator=(const socketPort& rhs)
|
|
//{
|
|
// if (this == &rhs) {
|
|
// return *this;
|
|
// }
|
|
//
|
|
// // TODO: assignment
|
|
//
|
|
// return *this;
|
|
//}
|
|
|
|
#endif // __SOCKETPORT_H_INCL__
|