1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96
|
/*__________________________________________________________________________
MusicBrainz -- The Internet music metadatabase
Portions Copyright (C) 2000 Relatable
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.
This library 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
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
$Id: comsocket.h,v 1.3 2000/09/29 12:15:05 ijr Exp $
____________________________________________________________________________*/
/***************************************************************************
comsocket.h - description
-------------------
begin : Thu Mar 23 2000
copyright : (C) 2000 by Relatable, LLC
programed by : Sean Ward
email : sward@relatable.com
***************************************************************************/
/// TODO: implement multicast connections (to allow single packet, multiple receiver connections)
#ifndef COMSOCKET_H
#define COMSOCKET_H
#include <stdio.h>
#include <string>
#ifdef WIN32
#include <winsock.h>
#else // ! WIN32
#include <sys/types.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <netdb.h>
#include <unistd.h>
#define INVALID_SOCKET -1
#endif // ! WIN32
class MBCOMServerSocket;
/**Wraps the OS specifics of a client socket.
*@author Sean Ward
*/
class MBCOMSocket {
public:
MBCOMSocket(int nSocket = INVALID_SOCKET, int nSockType = SOCK_STREAM);
~MBCOMSocket();
friend class MBCOMServerSocket;
/** Connects a socket to pIP, on nPort, of type nType. */
int Connect(const char* pIP, int nPort, int nType, bool
bBroadcast = false);
/** Checks if there is a current open connection */
bool IsConnected();
/** Disconnects the current socket */
int Disconnect();
/** Reads from a socket, into pbuffer, up to a max of nLen byte, and writes how many were actually written to nBytesWritten. */
int Read(char* pBuffer, int nLen, int* nBytesWritten);
/** Reads in a non blocking fashion (ie, selects and polls) for nTimeout seconds */
int NBRead(char* pBuffer, int nLen, int* nBytesWritten, int nTimeout);
/** Writes to a socket, from buffer pBuffer, up to nLen bytes, and returns the number of written bytes in pnBytesWritten. */
int Write(const char* pBuffer, int nLen, int* pnBytesWritten);
/** Sets TCPNODELAY to nFlag */
int SetNoDelay(int nFlag);
/** Sets NonBlocking status */
int SetNonBlocking(bool bType);
/** Connects in a non blocking fashion, to pIp, on port nPort, using a connection of type nType, with a timeout of nTimeout seconds */
int NBConnect(const char* pIP, int nPort, int nType, int nTimeout);
/** Sets multicast packets to only go through the NIC labeled pNIC */
int SetMCastInterface(const char* pNIC);
private: // Private attributes
/** The file descriptor for this socket */
int m_nSocket;
/** boolean to store connected state */
bool m_bConnected;
/** Stores the type of socket connection. IE, multicast, stream, datagram. */
int m_nSockType;
/** Stores the sockaddr describing this socket */
sockaddr_in m_SockAddr;
};
#endif
|