📄 macossocket.hpp
字号:
//// This file is part of the "More for C++" library//// Copyright (c) 1999-2003 by Thorsten Goertz (thorsten@morefor.org)//// The "More for C++" library is free software; you can redistribute it and/or// modify it under the terms of the license that comes with this package.//// Read "license.txt" for more details.//// THIS PACKAGE IS PROVIDED "AS IS" AND WITHOUT ANY EXPRESS OR IMPLIED// WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES// OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.////////////////////////////////////////////////////////////////////////////////#ifndef MACOSSOCKET_HPP#define MACOSSOCKET_HPP////////////////////////////////////////////////////////////////////////////////// "MacHeadersPPC" and the OT-Headers must have been included!#include <more/core/finalizable.hpp>#include <more/os/socket.hpp>using namespace more::core;using namespace more::os;////////////////////////////////////////////////////////////////////////////////namespace more{ namespace macos { class MacOSAcceptorSocket: public AcceptorSocket, public more::core::Finalizable { public: MacOSAcceptorSocket ( ); virtual bool isValid( ) const; virtual void bind( const String& sMask, size_t nNoOfPort ) throw( IOException ); virtual void bind( size_t nNoOfPort ) throw( IOException ); virtual String getNameOfHost( ) const; virtual size_t getNoOfPort( ) const; virtual p<Socket> accept( ) throw( IOException ); virtual void cancel( ) throw( IOException ); virtual void close( ) throw( IOException ); virtual void finalize( ); protected: void throwIfNotValid( ) const throw( IOException ); private: InetAddress m_ipAddress; EndpointRef m_pEndpoint; String m_sNameOfHost; size_t m_nNoOfPort; bool m_bHasBeenBound; bool m_bHasBeenCancelled; bool m_bIsBlockingInListen; }; //////////////////////////////////////////////////////////////////////// class MacOSSocket: public Socket, public Finalizable { public: MacOSSocket( ); MacOSSocket( EndpointRef pEndpoint ); virtual bool isValid( ) const; virtual void connect( const String& sNameOfHost, size_t nNoOfPort ) throw( IOException ); virtual String getNameOfHost( ) const; virtual size_t getNoOfPort( ) const; virtual p<InputStream> getInputStream ( ) throw( IOException ); virtual p<OutputStream> getOutputStream ( ) throw( IOException ); virtual void close( ) throw( IOException ); virtual void finalize( ); protected: void throwIfNotValid( ) const throw( IOException ); void throwIfNotConnected( ) const throw( IOException ); private: EndpointRef m_pEndpoint; bool m_bHasBeenBound; bool m_bHasBeenConnected; size_t m_nNoOfLastReadBytes; // For MacOSSocketInputStream: public: virtual size_t available( ) throw( IOException ); virtual bool hasBeenClosed( ) throw( IOException ); virtual size_t read( void* pBuffer, size_t nOffset, size_t nMaxNoOfBytes ) throw( IOException ); virtual size_t skip( size_t nNoOfBytes ) throw( IOException ); // For MacOSSocketOutputStream: public: virtual void write( const void* pBuffer, size_t nNoOfBytes ) throw( IOException ); virtual void flush( ) throw( IOException ); }; //////////////////////////////////////////////////////////////////////// class MacOSSocketInputStream: public InputStream { public: MacOSSocketInputStream( p<MacOSSocket> ); virtual size_t available( ) throw( IOException ); virtual bool hasBeenClosed( ) throw( IOException ); virtual size_t read( void* pBuffer, size_t nOffset, size_t nMaxNoOfBytes ) throw( IOException ); virtual size_t skip( size_t nNoOfBytes ) throw( IOException ); private: p<MacOSSocket> m_pMacOSSocket; }; //////////////////////////////////////////////////////////////////////// class MacOSSocketOutputStream: public OutputStream { public: MacOSSocketOutputStream ( p<MacOSSocket> ); virtual void write( const void* pBuffer, size_t nNoOfBytes ) throw( IOException ); virtual void flush( ) throw( IOException ); private: p<MacOSSocket> m_pMacOSSocket; }; //////////////////////////////////////////////////////////////////////// inline void MacOSAcceptorSocket::throwIfNotValid( ) const throw( IOException ) { if( !isValid( ) ) { throw IOException( -1, "Invalid socket" ); } } //////////////////////////////////////////////////////////////////////// inline void MacOSSocket::throwIfNotValid( ) const throw( IOException ) { if( !isValid( ) ) { throw IOException( -1, "Invalid socket" ); } } //////////////////////////////////////////////////////////////////////// inline void MacOSSocket::throwIfNotConnected( ) const throw( IOException ) { if( !m_bHasBeenConnected ) { throw IOException( -1, "Socket has not been connected" ); } } }}////////////////////////////////////////////////////////////////////////////////#endif
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -