Main Page | Namespace List | Class Hierarchy | Alphabetical List | Class List | File List | Namespace Members | Class Members | File Members | Related Pages

MCSocket.h

00001 #if !defined(__MCSOCKET_H_)
00002 #define __MCSOCKET_H_
00003 
00004 #ident "@(#)$Id: MCSocket.h,v 1.5 2004/12/02 07:05:20 mike Exp $"
00005 
00006 /*
00007  * Copyright Miba Consulting Ltd. (c) 2000-2003
00008  * 
00009  * This library is free software; you can redistribute it and/or
00010  * modify it under the terms of the GNU Lesser General Public
00011  * License as published by the Free Software Foundation; either
00012  * version 2.1 of the License, or (at your option) any later version.
00013  * 
00014  * This library is distributed in the hope that it will be useful,
00015  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00016  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
00017  * Lesser General Public License for more details.
00018  * 
00019  * You should have received a copy of the GNU Lesser General Public
00020  * License along with this library; if not, write to the Free Software
00021  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
00022  *
00023  */
00024 
00025 #include "mcllib/MCIOBase.h"
00026 #include "mcllib/MCTime.h"
00027 #include "mcllib/MCString.h"
00028 
00029 namespace mclpriv {
00030     // Forward declaration
00031     class MCNetAddrFactory;
00032 };
00033 
00034 namespace mcllib
00035 {
00036     // Forward declaration
00037     class MCRecvFromResult;
00038 
00044     class MCNetAddr : public MCBase
00045     {
00046     public:
00052         const void* getAddr() const;
00057         MCString toString() const;
00058     private:
00059         friend class mclpriv::MCNetAddrFactory;
00060         friend class MCRecvFromResult;
00061 
00063         MCNetAddr(void* impl);
00064     };
00065 
00072     class MCRecvFromResult
00073     {
00074     public:
00079         mcuint32 getRecvSize() const;
00084         const MCNetAddr& getRecvFrom() const;
00085 
00086     private:
00087         friend class mclpriv::MCNetAddrFactory;
00089         MCRecvFromResult(mcuint32 size, void* impl);
00090         mcuint32 m_recvSize;
00091         MCNetAddr m_recvFrom;
00092     };
00093 
00097     enum MCEAddrType
00098     {
00100         MCAFRAW,
00102         MCAFINET,
00104         MCAFINETV6,
00106         MCAFPATH
00107     };
00108 
00114     extern const mcuint16 MCAnyPort;
00115 
00116     // Network address functions
00122     MCNetAddr MCGetInetAddrAny(mcuint16 port = MCAnyPort);
00129     MCNetAddr MCGetInetAddr(const MCString& name, mcuint16 port = MCAnyPort);
00136     MCNetAddr MCGetPathAddr(const MCString& path);
00137 
00144     class MCSocket : public MCIOBase
00145     {
00146     public:
00151         ~MCSocket();
00152 
00167         mcint32 sendTo(const MCNetAddr& addr,
00168             const void* buf, mcint32 len,
00169             mcinterval_t timeout = MCIntervalInfinite);
00182         MCRecvFromResult recvFrom(void* buf,
00183             mcint32 len,
00184             mcinterval_t timeout = MCIntervalInfinite);
00190         MCNetAddr getSockName() const;
00196         void bind(const MCNetAddr& addr);
00197         //
00198         // Common Socket options - across all socket types
00199         //
00206         bool getNonBlock() const;
00216         bool getReuseAddr() const;
00221         mcuint32 getSendBufferSize() const;
00226         mcuint32 getRecvBufferSize() const;
00231         mcuint32 getTtl() const;
00236         mcuint32 getTos() const;
00241         void setNonBlock(bool nonBlock);
00247         void setReuseAddr(bool reuse);
00252         void setSendBufferSize(mcuint32 sz);
00257         void setRecvBufferSize(mcuint32 sz);
00262         void setTtl(mcuint32 ttl);
00267         void setTos(mcuint32 tos);
00268 
00269     protected:
00271         MCSocket();
00276         MCSocket(void* impl);
00277     };
00278 
00286     class MCCOSocket : public MCSocket
00287     {
00288     public:
00295         MCNetAddr getPeerName() const;
00307         mcint32 send(const void* buf, mcint32 len,
00308             mcinterval_t timeout = MCIntervalInfinite);
00320         mcint32 recv(void* buf, mcint32 len,
00321             mcinterval_t timeout = MCIntervalInfinite);
00327         mcint32 peek(void* buf, mcint32 len,
00328             mcinterval_t timeout = MCIntervalInfinite);
00338         void connect(const MCNetAddr& addr,
00339             mcinterval_t timeout = MCIntervalInfinite);
00340 
00341     protected:
00343         MCCOSocket();
00348         MCCOSocket(void* impl);
00349     };
00350 
00365     class MCCLSocket : public MCSocket
00366     {
00367     public:
00368         // Connection less specific options
00373         bool getBroadcast() const;
00378         void setBroadcast(bool broadcast);
00383         mcuint32 getMulticastTtl() const;
00388         void setMulticastTtl(mcuint32 mcastTtl);
00393         MCNetAddr getMulticastIf() const;
00398         void setMulticastIf(const MCNetAddr& mcastIf);
00404         void addMulticast(const MCNetAddr& group, const MCNetAddr& mcastIf);
00410         void dropMulticast(const MCNetAddr& group, const MCNetAddr& mcastIf);
00411     protected:
00413         MCCLSocket();
00418         MCCLSocket(void* impl);
00419     };
00420 
00421 
00426     class MCStreamSocket : public MCCOSocket
00427     {
00428     public:
00430         virtual ~MCStreamSocket();
00446         virtual void accept(MCStreamSocket* pSock,
00447             mcinterval_t timeout = MCIntervalInfinite);
00456         void listen(mcintn queueLength);
00458         void shutdownSend();
00460         void shutdownRecv();
00461         // TCP Socket options
00466         bool getKeepAlive() const;
00477         void setKeepAlive(bool keepAlive);
00483         mcinterval_t getLingerTime() const;
00488         bool getLinger() const;
00499         void setLinger(bool linger, mcinterval_t timeout);
00504         bool getNoDelay() const;
00517         void setNoDelay(bool noDelay);
00522         mcuint32 getMss() const;
00527         void setMss(mcuint32 mss);
00528     protected:
00530         MCStreamSocket();
00535         MCStreamSocket(void* impl);
00536     private:
00538         virtual void acceptIf(MCStreamSocket* pSock, mcinterval_t timeout) = 0;
00539     };
00540 
00545     class MCTCPSocket : public MCStreamSocket
00546     {
00547     public:
00553         MCTCPSocket();
00560         MCTCPSocket(const MCNetAddr& addr);
00561         // From MCStreamSocket
00563         virtual ~MCTCPSocket();
00564     private:
00565         friend class MCStreamSocket;
00566         MCTCPSocket(void* impl);
00567         // from MCStreamSocket
00568         virtual void acceptIf(MCStreamSocket* pSock, mcinterval_t timeout);
00569     };
00570 
00578     class MCCOUDPSocket : public MCCOSocket
00579     {
00580     public:
00586         MCCOUDPSocket();
00593         MCCOUDPSocket(const MCNetAddr& addr);
00594     };
00595 
00603     class MCUDPSocket : public MCCLSocket
00604     {
00605     public:
00611         MCUDPSocket();
00618         MCUDPSocket(const MCNetAddr& addr);
00619     };
00620 };
00621 
00622 
00623 #endif

Generated on Wed Jan 12 19:05:48 2005 for MCLLIB by  doxygen 1.3.9.1