2003-01-04 22:01:32 +00:00
|
|
|
/*
|
|
|
|
* synergy -- mouse and keyboard sharing utility
|
|
|
|
* Copyright (C) 2002 Chris Schoeneman
|
|
|
|
*
|
|
|
|
* This package is free software you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU General Public License
|
|
|
|
* found in the file COPYING that should have accompanied this file.
|
|
|
|
*
|
|
|
|
* This package is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef CARCHNETWORKBSD_H
|
|
|
|
#define CARCHNETWORKBSD_H
|
|
|
|
|
|
|
|
#include "IArchNetwork.h"
|
|
|
|
#include "IArchMultithread.h"
|
2004-05-01 11:01:40 +00:00
|
|
|
#if HAVE_SYS_TYPES_H
|
|
|
|
# include <sys/types.h>
|
|
|
|
#endif
|
2003-01-04 22:01:32 +00:00
|
|
|
#if HAVE_SYS_SOCKET_H
|
|
|
|
# include <sys/socket.h>
|
|
|
|
#endif
|
|
|
|
|
2004-10-28 21:40:56 +00:00
|
|
|
#if !HAVE_SOCKLEN_T
|
2003-01-04 22:01:32 +00:00
|
|
|
typedef int socklen_t;
|
|
|
|
#endif
|
|
|
|
|
2004-03-08 20:45:53 +00:00
|
|
|
// old systems may use char* for [gs]etsockopt()'s optval argument.
|
|
|
|
// this should be void on modern systems but char is forwards
|
|
|
|
// compatible so we always use it.
|
|
|
|
typedef char optval_t;
|
|
|
|
|
2003-01-04 22:01:32 +00:00
|
|
|
#define ARCH_NETWORK CArchNetworkBSD
|
|
|
|
|
|
|
|
class CArchSocketImpl {
|
|
|
|
public:
|
|
|
|
int m_fd;
|
|
|
|
int m_refCount;
|
|
|
|
};
|
|
|
|
|
|
|
|
class CArchNetAddressImpl {
|
|
|
|
public:
|
|
|
|
CArchNetAddressImpl() : m_len(sizeof(m_addr)) { }
|
|
|
|
|
|
|
|
public:
|
|
|
|
struct sockaddr m_addr;
|
|
|
|
socklen_t m_len;
|
|
|
|
};
|
|
|
|
|
2003-01-05 21:48:54 +00:00
|
|
|
//! Berkeley (BSD) sockets implementation of IArchNetwork
|
2003-01-04 22:01:32 +00:00
|
|
|
class CArchNetworkBSD : public IArchNetwork {
|
|
|
|
public:
|
|
|
|
CArchNetworkBSD();
|
|
|
|
virtual ~CArchNetworkBSD();
|
|
|
|
|
|
|
|
// IArchNetwork overrides
|
|
|
|
virtual CArchSocket newSocket(EAddressFamily, ESocketType);
|
|
|
|
virtual CArchSocket copySocket(CArchSocket s);
|
|
|
|
virtual void closeSocket(CArchSocket s);
|
|
|
|
virtual void closeSocketForRead(CArchSocket s);
|
|
|
|
virtual void closeSocketForWrite(CArchSocket s);
|
|
|
|
virtual void bindSocket(CArchSocket s, CArchNetAddress addr);
|
|
|
|
virtual void listenOnSocket(CArchSocket s);
|
|
|
|
virtual CArchSocket acceptSocket(CArchSocket s, CArchNetAddress* addr);
|
2004-02-29 16:11:17 +00:00
|
|
|
virtual bool connectSocket(CArchSocket s, CArchNetAddress name);
|
2003-01-04 22:01:32 +00:00
|
|
|
virtual int pollSocket(CPollEntry[], int num, double timeout);
|
2004-02-28 12:19:49 +00:00
|
|
|
virtual void unblockPollSocket(CArchThread thread);
|
2003-01-04 22:01:32 +00:00
|
|
|
virtual size_t readSocket(CArchSocket s, void* buf, size_t len);
|
|
|
|
virtual size_t writeSocket(CArchSocket s,
|
|
|
|
const void* buf, size_t len);
|
|
|
|
virtual void throwErrorOnSocket(CArchSocket);
|
|
|
|
virtual bool setNoDelayOnSocket(CArchSocket, bool noDelay);
|
|
|
|
virtual std::string getHostName();
|
|
|
|
virtual CArchNetAddress newAnyAddr(EAddressFamily);
|
|
|
|
virtual CArchNetAddress copyAddr(CArchNetAddress);
|
|
|
|
virtual CArchNetAddress nameToAddr(const std::string&);
|
|
|
|
virtual void closeAddr(CArchNetAddress);
|
|
|
|
virtual std::string addrToName(CArchNetAddress);
|
|
|
|
virtual std::string addrToString(CArchNetAddress);
|
|
|
|
virtual EAddressFamily getAddrFamily(CArchNetAddress);
|
|
|
|
virtual void setAddrPort(CArchNetAddress, int port);
|
|
|
|
virtual int getAddrPort(CArchNetAddress);
|
|
|
|
virtual bool isAnyAddr(CArchNetAddress);
|
2004-02-14 14:04:36 +00:00
|
|
|
virtual bool isEqualAddr(CArchNetAddress, CArchNetAddress);
|
2003-01-04 22:01:32 +00:00
|
|
|
|
|
|
|
private:
|
2004-02-29 16:48:22 +00:00
|
|
|
const int* getUnblockPipe();
|
|
|
|
const int* getUnblockPipeForThread(CArchThread);
|
2004-02-29 16:11:17 +00:00
|
|
|
void setBlockingOnSocket(int fd, bool blocking);
|
2003-01-04 22:01:32 +00:00
|
|
|
void throwError(int);
|
|
|
|
void throwNameError(int);
|
|
|
|
|
|
|
|
private:
|
|
|
|
CArchMutex m_mutex;
|
|
|
|
};
|
|
|
|
|
|
|
|
#endif
|