📄 tcpsocket.h
字号:
#ifndef TCPSOCKET_H#define TCPSOCKET_H/********************************************************************* $Id: TCPSocket.h,v 1.2 1999/08/31 02:22:05 cullen Exp $ ********************************************************************* 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 of the License, or (at your option) any later version. In addition to the terms and conditions set forth in the GNU Lesser General Public License, as a condition of using this library you are required to grant to all users of this library or any implementation utilizing or derived from this library a reciprocal, no cost, worldwide, perpetual, non-exclusive, non-transferable, unrestricted license to your claims of all patents and patent applications throughout the world that are infringed by the library or any implementation utilizing or derived from this library. In the event you redistribute this library or any implementation utilizing or derived from this library, you must prominently display the foregoing terms and conditions with the library or the implementation utilizing or derived from this library. In the event of a conflict of terms between the foregoing license grant and the terms set forth in the GNU Lesser General Public License, the foregoing terms and conditions shall be deemed to govern. 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. Copyright 1999 Vovida Networks, Inc. All Rights Reserved. ********************************************************************* $Log: TCPSocket.h,v $ Revision 1.2 1999/08/31 02:22:05 cullen updated header **********************************************************************/#include <iostream.h>#include <errno.h>#include <sys/socket.h>#include <sys/time.h>#include <netinet/in.h>#include <unistd.h>#include "IPAddress.h"#include "Mutex.h"#include "mhtypes.h" namespace mh323{ class TCPSocket { public: TCPSocket(uint iPort = 0 ); void printOn(ostream & xStr); void bind( uint iPort); void connect(const IPAddress& xRemoteAddress); void listen(int iBackLog = 5); void accept(TCPSocket& xListener); void send(const void * cpBuf, int iBufLen, int iFlag=0); void recv(void * cpBuf, int iBufLen, int iFlag=0); int recvAll(void * cpBuf, int iBufLen, int iFlag=0); void SetTimer(TimeInterval Time); TimeInterval GetTimer(void); void ClearTimer(); bool isTimerValid(); void waitForInput(void); void waitForOutputAvail(void); bool isInputAvail(); void cancel(); void stopWaiting(); ~TCPSocket (); int getDescriptor() const { return m_ihSocket; } const IPAddress & getAddress() const { return m_xInetAddr; } protected: int m_ihSocket; // Socket Descriptor int m_iDomain; int m_iType; int m_iProtocol; bool m_bStopReceived; bool m_bConnected; IPAddress m_xInetAddr; struct timeval m_xInitTime; TimeInterval m_iTimer; Mutex m_xMutex; Mutex m_xCancel; int m_xPipeChan[2]; };}#endif TCPSOCKET_H
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -