| 1 | /* | 
|---|
| 2 | * synergy -- mouse and keyboard sharing utility | 
|---|
| 3 | * Copyright (C) 2002 Chris Schoeneman | 
|---|
| 4 | * | 
|---|
| 5 | * This package is free software; you can redistribute it and/or | 
|---|
| 6 | * modify it under the terms of the GNU General Public License | 
|---|
| 7 | * found in the file COPYING that should have accompanied this file. | 
|---|
| 8 | * | 
|---|
| 9 | * This package is distributed in the hope that it will be useful, | 
|---|
| 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | 
|---|
| 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the | 
|---|
| 12 | * GNU General Public License for more details. | 
|---|
| 13 | */ | 
|---|
| 14 |  | 
|---|
| 15 | #ifndef XSOCKET_H | 
|---|
| 16 | #define XSOCKET_H | 
|---|
| 17 |  | 
|---|
| 18 | #include "XIO.h" | 
|---|
| 19 | #include "XBase.h" | 
|---|
| 20 | #include "CString.h" | 
|---|
| 21 | #include "BasicTypes.h" | 
|---|
| 22 |  | 
|---|
| 23 | //! Generic socket exception | 
|---|
| 24 | XBASE_SUBCLASS(XSocket, XBase); | 
|---|
| 25 |  | 
|---|
| 26 | //! Socket bad address exception | 
|---|
| 27 | /*! | 
|---|
| 28 | Thrown when attempting to create an invalid network address. | 
|---|
| 29 | */ | 
|---|
| 30 | class XSocketAddress : public XSocket { | 
|---|
| 31 | public: | 
|---|
| 32 | //! Failure codes | 
|---|
| 33 | enum EError { | 
|---|
| 34 | kUnknown,               //!< Unknown error | 
|---|
| 35 | kNotFound,              //!< The hostname is unknown | 
|---|
| 36 | kNoAddress,             //!< The hostname is valid but has no IP address | 
|---|
| 37 | kUnsupported,   //!< The hostname is valid but has no supported address | 
|---|
| 38 | kBadPort                //!< The port is invalid | 
|---|
| 39 | }; | 
|---|
| 40 |  | 
|---|
| 41 | XSocketAddress(EError, const CString& hostname, int port) throw(); | 
|---|
| 42 |  | 
|---|
| 43 | //! @name accessors | 
|---|
| 44 | //@{ | 
|---|
| 45 |  | 
|---|
| 46 | //! Get the error code | 
|---|
| 47 | EError                          getError() const throw(); | 
|---|
| 48 | //! Get the hostname | 
|---|
| 49 | CString                         getHostname() const throw(); | 
|---|
| 50 | //! Get the port | 
|---|
| 51 | int                                     getPort() const throw(); | 
|---|
| 52 |  | 
|---|
| 53 | //@} | 
|---|
| 54 |  | 
|---|
| 55 | protected: | 
|---|
| 56 | // XBase overrides | 
|---|
| 57 | virtual CString         getWhat() const throw(); | 
|---|
| 58 |  | 
|---|
| 59 | private: | 
|---|
| 60 | EError                          m_error; | 
|---|
| 61 | CString                         m_hostname; | 
|---|
| 62 | int                                     m_port; | 
|---|
| 63 | }; | 
|---|
| 64 |  | 
|---|
| 65 | //! I/O closing exception | 
|---|
| 66 | /*! | 
|---|
| 67 | Thrown if a stream cannot be closed. | 
|---|
| 68 | */ | 
|---|
| 69 | XBASE_SUBCLASS_FORMAT(XSocketIOClose, XIOClose); | 
|---|
| 70 |  | 
|---|
| 71 | //! Socket cannot bind address exception | 
|---|
| 72 | /*! | 
|---|
| 73 | Thrown when a socket cannot be bound to an address. | 
|---|
| 74 | */ | 
|---|
| 75 | XBASE_SUBCLASS_FORMAT(XSocketBind, XSocket); | 
|---|
| 76 |  | 
|---|
| 77 | //! Socket address in use exception | 
|---|
| 78 | /*! | 
|---|
| 79 | Thrown when a socket cannot be bound to an address because the address | 
|---|
| 80 | is already in use. | 
|---|
| 81 | */ | 
|---|
| 82 | XBASE_SUBCLASS(XSocketAddressInUse, XSocketBind); | 
|---|
| 83 |  | 
|---|
| 84 | //! Cannot connect socket exception | 
|---|
| 85 | /*! | 
|---|
| 86 | Thrown when a socket cannot connect to a remote endpoint. | 
|---|
| 87 | */ | 
|---|
| 88 | XBASE_SUBCLASS_FORMAT(XSocketConnect, XSocket); | 
|---|
| 89 |  | 
|---|
| 90 | //! Cannot create socket exception | 
|---|
| 91 | /*! | 
|---|
| 92 | Thrown when a socket cannot be created (by the operating system). | 
|---|
| 93 | */ | 
|---|
| 94 | XBASE_SUBCLASS_FORMAT(XSocketCreate, XSocket); | 
|---|
| 95 |  | 
|---|
| 96 | #endif | 
|---|