#pragma once

#include <sys/types.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <netinet/ip.h>

#include "CComm.h"

class CSocket final : public CComm
{
public:
	typedef struct
	{
		char *ipAddr;
		int nPort;
	} CONNECTION;

	CSocket();
	~CSocket();

	bool Open(void *p) override;
	void Close() override;

	error_t Receive() override;
	size_t Transmit(const uint8_t *buf, size_t toWriteBytes) override;

private:
	static void *ThreadFunc(void *p);

	bool terminated_;
	int sock_fd_;
};