MOOS 0.2375
/home/toby/moos-ivp/MOOS-2375-Oct0611/Core/MOOSLIB/XPCTcpSocket.h
Go to the documentation of this file.
00001 
00002 //
00003 //   MOOS - Mission Oriented Operating Suite 
00004 //  
00005 //   A suit of Applications and Libraries for Mobile Robotics Research 
00006 //   Copyright (C) 2001-2005 Massachusetts Institute of Technology and 
00007 //   Oxford University. 
00008 //    
00009 //   This software was written by Paul Newman at MIT 2001-2002 and Oxford 
00010 //   University 2003-2005. email: pnewman@robots.ox.ac.uk. 
00011 //      
00012 //   This file is part of a  MOOS CORE Component. 
00013 //        
00014 //   This program is free software; you can redistribute it and/or 
00015 //   modify it under the terms of the GNU General Public License as 
00016 //   published by the Free Software Foundation; either version 2 of the 
00017 //   License, or (at your option) any later version. 
00018 //          
00019 //   This program is distributed in the hope that it will be useful, 
00020 //   but WITHOUT ANY WARRANTY; without even the implied warranty of 
00021 //   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 
00022 //   General Public License for more details. 
00023 //            
00024 //   You should have received a copy of the GNU General Public License 
00025 //   along with this program; if not, write to the Free Software 
00026 //   Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 
00027 //   02111-1307, USA. 
00028 //
00029 //   The XPC classes in MOOS are modified versions of the source provided 
00030 //   in "Making UNIX and Windows NT Talk" by Mark Nadelson and Thomas Haga 
00031 //
00033 
00034 
00035 #ifndef _XPCTcpSocket
00036 #define _XPCTcpSocket
00037 
00038 #include "XPCSocket.h"
00039 
00040 #ifdef WINDOWS_NT
00041 #ifndef MSG_WAITALL
00042 #define MSG_WAITALL 4
00043 #endif
00044 #endif
00045 
00046 class XPCTcpSocket : public XPCSocket
00047 {
00048 private:
00049 #ifdef WINDOWS_NT
00050     // Windows NT version of the MSG_WAITALL option
00051     int iRecieveMessageAll(void *_vMessage, int _iMessageSize);
00052 #endif
00053 public:
00054 
00055     // Constructor.  Used to create a new TCP socket given a port
00056     XPCTcpSocket(long int _iPort) : XPCSocket("tcp", _iPort) { };
00057 
00058     // Constructor.  Called when a client connects and a new file descriptor has
00059     // be created as a result.    
00060     XPCTcpSocket(short int _iSocketFd) : XPCSocket(_iSocketFd) { };
00061 
00062     // Sends a message to a connected host. The number of bytes sent is returned
00063     int iSendMessage(void *_vMessage, int _iMessageSize);
00064 
00065     // Receives a TCP message 
00066     int iRecieveMessage(void *_vMessage, int _iMessageSize, int _iOption = 0);
00067 
00068     // Binds the socket to an address and port number
00069     void vBindSocket();
00070 
00071     // Accepts a connecting client.  The address of the connected client is stored in the
00072     // parameter
00073     XPCTcpSocket *Accept(char *_sHost = NULL);
00074 
00075     // Listens to connecting clients
00076     void vListen(int _iNumPorts = 5);
00077 
00078     // Connects to a client specified by a supplied host name
00079     virtual void vConnect(const char *_sHost);
00080 
00081     // allows a read with a timeout to prevent from blocking indefinitely
00082     int iReadMessageWithTimeOut(void *_vMessage, int _iMessageSize, double dfTimeOut,int _iOption=0);
00083 
00084 };
00085 
00086 #endif
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines