⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 win32socket.hpp

📁 "More for C++" is a class library that provides some features that are usually common for object ori
💻 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 WIN32SOCKET_HPP#define WIN32SOCKET_HPP////////////////////////////////////////////////////////////////////////////////// "windows.h" must have been included!!!#include <more/core/finalizable.hpp>#include <more/os/socket.hpp>////////////////////////////////////////////////////////////////////////////////namespace more{  namespace os  {    namespace win32    {      class Win32SocketAddress      {        public:          Win32SocketAddress( struct sockaddr_in&  sockAddrIn );          virtual void resolve( const String&  sNameOfHost, int nNoOfPort ) throw( IOException );        private:          struct sockaddr_in& m_sockAddrIn;      };      ////////////////////////////////////////////////////////////////////////      class Win32AcceptorSocket: public AcceptorSocket, public more::core::Finalizable      {        public:          Win32AcceptorSocket  ( );          virtual void finalize( );          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 );        protected:          virtual void throwIfNotValid( ) throw( IOException );        private:          SOCKET              m_socket;          int                 m_nNoOfPort;          struct sockaddr_in  m_sockAddrIn;          bool                m_bHasBeenCancelled;      };      ////////////////////////////////////////////////////////////////////////      class Win32Socket: public Socket, public more::core::Finalizable      {        public:          Win32Socket( );          Win32Socket( SOCKET socket, sockaddr_in& sockAddrIn );          virtual void finalize( );          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<more::io::InputStream> getInputStream ( ) throw( more::io::IOException );          virtual p<more::io::OutputStream>  getOutputStream ( ) throw( more::io::IOException );          virtual void close( ) throw( IOException );        protected:          void throwIfNotValid( ) const throw( IOException );          void throwIfNotConnected( ) const throw( IOException );        private:          SOCKET              m_socket;          struct sockaddr_in  m_sockAddrIn;          bool                m_bHasBeenConnected;        // For Win32SocketInputStream/Win32SocketOutputStream:        public:          virtual size_t available( ) throw( more::io::IOException );          virtual bool hasBeenClosed( ) throw( more::io::IOException );          virtual size_t skip( size_t nNoOfBytes ) throw( more::io::IOException );          virtual size_t read( void* pBuffer, size_t  nMaxNoOfBytes ) throw( more::io::IOException );          virtual void write( const void*  pBuffer, size_t nNoOfBytes ) throw( more::io::IOException );          virtual size_t rewind( size_t nNoOfBytes ) throw( more::io::IOException );          virtual void flush( ) throw( more::io::IOException );      };      ////////////////////////////////////////////////////////////////////////      class Win32SocketInputStream: public more::io::InputStream      {        public:          Win32SocketInputStream( p<Win32Socket> );          virtual size_t available( ) throw( more::io::IOException );          virtual bool hasBeenClosed( ) throw( more::io::IOException );          virtual size_t skip( size_t nNoOfBytes ) throw( more::io::IOException );          virtual size_t read( void* pBuffer, size_t nMaxNoOfBytes ) throw( more::io::IOException );        private:          p<Win32Socket> m_pWin32Socket;      };      ////////////////////////////////////////////////////////////////////////      class Win32SocketOutputStream: public more::io::OutputStream      {        public:          Win32SocketOutputStream ( p<Win32Socket> );          virtual void write( const void*  pBuffer, size_t nNoOfBytes ) throw( more::io::IOException );          virtual size_t rewind( size_t nNoOfBytes ) throw( more::io::IOException );          virtual bool hasBeenClosed( ) throw( more::io::IOException );          virtual void flush( ) throw( more::io::IOException );        private:          p<Win32Socket> m_pWin32Socket;      };    }  }}////////////////////////////////////////////////////////////////////////////////inline void more::os::win32::Win32AcceptorSocket::throwIfNotValid( ){  if( !isValid( ) )  {    throw IOException( -1, "Invalid socket" );  }}////////////////////////////////////////////////////////////////////////////////inline void more::os::win32::Win32Socket::throwIfNotValid( ) const{  if( !isValid( ) )  {    throw IOException( -1, "Invalid socket" );  }}////////////////////////////////////////////////////////////////////////////////inline void more::os::win32::Win32Socket::throwIfNotConnected( ) const{  if( !m_bHasBeenConnected )  {    throw IOException( -1, "Socket has not been connected" );  }}////////////////////////////////////////////////////////////////////////////////#endif

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -