Main Page | Namespace List | Class Hierarchy | Alphabetical List | Class List | Directories | File List | Namespace Members | Class Members | File Members

SocketAccessor.h

Go to the documentation of this file.
00001 /*
00002  * SocketAccessor.h
00003  *
00004  * Smalltalk like class library for C++
00005  * Accessor to BSD socket. Header.
00006  *
00007  * Copyright (c) 2004 Milan Cermak
00008  */
00009 /*
00010  * This library is free software; you can redistribute it and/or
00011  * modify it under the terms of the GNU Lesser General Public
00012  * License as published by the Free Software Foundation; either
00013  * version 2.1 of the License, or (at your option) any later version.
00014  *
00015  * This library is distributed in the hope that it will be useful,
00016  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00017  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00018  * Lesser General Public License for more details.
00019  *
00020  * You should have received a copy of the GNU Lesser General Public
00021  * License along with this library; if not, write to the Free Software
00022  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00023  */
00024 #ifndef __SOCKETACCESSOR_H
00025 #define __SOCKETACCESSOR_H
00026 
00027 #include <stlib/IOAccessor.h>
00028 #include <stlib/ByteArray.h>
00029 #include <stlib/String.h>
00030 #include <stlib/GenericException.h>
00031 
00037 namespace Net {
00038 
00039 class IPSocketAddress;
00040 
00041 class SocketAccessor : public Core::IOAccessor
00042 {
00043   protected:
00045     int descriptor;
00046     int sckFamily;
00047 
00048   protected:
00050     SocketAccessor(int descr);
00051 
00052   public:
00053     SocketAccessor(int family, int type, int protocol = 0);
00054 
00055     /* Instance creation protocol */
00056     static SocketAccessor *newTCP(void);
00057     static SocketAccessor *newTCPclientToHost(ByteArray *hostAddr, int port);
00058     static SocketAccessor *newTCPclientToHost(String *hostName, int port);
00059     static SocketAccessor *newTCPserverAtPort(int port);
00060     static SocketAccessor *newTCPserverAt(ByteArray *hostAddr, int port);
00061     static SocketAccessor *newUDP(void);
00062     static SocketAccessor *newUDPclientToHost(ByteArray *hostAddr, int port);
00063     static SocketAccessor *newUDPclientToHost(String *hostName, int port);
00064     static SocketAccessor *newUDPserverAtPort(int port);
00065     static SocketAccessor *newUDPserverAt(ByteArray *hostAddr, int port);
00066 
00067     /* Class-accessing protocol */
00068     virtual String *className(void) const;
00069     static String *getHostname(void);
00070 
00071     /* Initialize-release protocol */
00072     virtual void close(void);
00073 
00074     /* Accessing protocol */
00075     virtual long bufferSize(void);
00076     virtual IPSocketAddress *myAddress(void);
00077     virtual IPSocketAddress *peerAddress(void);
00078 
00079     /* Data transfer protocol */
00080     virtual int readInto(ByteArray *buffer)
00081       { return IOAccessor::readInto(buffer); }
00082     virtual int readInto(ByteArray *buffer, long startIndex, long count);
00083 
00084     virtual int writeFrom(ByteArray *buffer)
00085       { return IOAccessor::writeFrom(buffer); }
00086     virtual int writeFrom(ByteArray *buffer, long startIndex, long count);
00087 
00088     /* Positioning protocol */
00089     virtual void seekTo(long position);
00090 
00091     /* Synchronization protocol */
00092     virtual void readWait(void);
00093     virtual bool readWaitWithTimeout(int milliseconds);
00094     virtual void writeWait(void);
00095     virtual bool writeWaitWithTimeout(int milliseconds);
00096 
00097     /* State transitions protocol */
00098     virtual void bindTo(IPSocketAddress *address);
00099     virtual void connectTo(IPSocketAddress *address);
00100     virtual void listenFor(int queueLength);
00101 
00102     /* Instance creation protocol */
00103     virtual SocketAccessor *accept(void);
00104 };
00105 
00106 };
00107 
00108 #endif /* __SOCKETACCESSOR_H */

Generated on Mon Nov 27 09:47:55 2006 for Smalltalk like C++ Class Library by  doxygen 1.4.2