trim headers and unused code in IXUdpSocket

This commit is contained in:
Benjamin Sergeant
2020-03-22 21:51:41 -07:00
parent b7e7837d76
commit f72f845ad2
5 changed files with 24 additions and 74 deletions

View File

@ -7,28 +7,13 @@
#include "IXUdpSocket.h"
#include "IXNetSystem.h"
#include "IXSelectInterrupt.h"
#include "IXSelectInterruptFactory.h"
#include "IXSocketConnect.h"
#include <algorithm>
#include <assert.h>
#include <fcntl.h>
#include <sstream>
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/types.h>
#ifdef min
#undef min
#endif
#include <strings.h>
namespace ix
{
UdpSocket::UdpSocket(int fd)
: _sockfd(fd)
, _selectInterrupt(createSelectInterrupt())
{
;
}
@ -40,8 +25,6 @@ namespace ix
void UdpSocket::close()
{
std::lock_guard<std::mutex> lock(_socketMutex);
if (_sockfd == -1) return;
closeSocket(_sockfd);
@ -61,18 +44,6 @@ namespace ix
return err;
}
bool UdpSocket::isWaitNeeded()
{
int err = getErrno();
if (err == EWOULDBLOCK || err == EAGAIN || err == EINPROGRESS)
{
return true;
}
return false;
}
void UdpSocket::closeSocket(int fd)
{
#ifdef _WIN32

View File

@ -7,59 +7,34 @@
#pragma once
#include <atomic>
#include <functional>
#include <memory>
#include <mutex>
#include <string>
#ifdef _WIN32
#include <BaseTsd.h>
typedef SSIZE_T ssize_t;
#undef EWOULDBLOCK
#undef EAGAIN
#undef EINPROGRESS
#undef EBADF
#undef EINVAL
// map to WSA error codes
#define EWOULDBLOCK WSAEWOULDBLOCK
#define EAGAIN WSATRY_AGAIN
#define EINPROGRESS WSAEINPROGRESS
#define EBADF WSAEBADF
#define EINVAL WSAEINVAL
#endif
#include "IXCancellationRequest.h"
#include "IXNetSystem.h"
namespace ix
{
class SelectInterrupt;
class UdpSocket
{
public:
UdpSocket(int fd = -1);
virtual ~UdpSocket();
~UdpSocket();
// Virtual methods
bool init(const std::string& host, int port, std::string& errMsg);
ssize_t sendto(const std::string& buffer);
virtual void close();
void close();
static int getErrno();
static bool isWaitNeeded();
static void closeSocket(int fd);
protected:
std::atomic<int> _sockfd;
std::mutex _socketMutex;
struct sockaddr_in _server;
private:
std::shared_ptr<SelectInterrupt> _selectInterrupt;
std::atomic<int> _sockfd;
struct sockaddr_in _server;
};
} // namespace ix