| 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 | #include "XSocket.h" | 
|---|
| 16 | #include "CStringUtil.h" | 
|---|
| 17 |  | 
|---|
| 18 | // | 
|---|
| 19 | // XSocketAddress | 
|---|
| 20 | // | 
|---|
| 21 |  | 
|---|
| 22 | XSocketAddress::XSocketAddress(EError error, | 
|---|
| 23 | const CString& hostname, int port) throw() : | 
|---|
| 24 | m_error(error), | 
|---|
| 25 | m_hostname(hostname), | 
|---|
| 26 | m_port(port) | 
|---|
| 27 | { | 
|---|
| 28 | // do nothing | 
|---|
| 29 | } | 
|---|
| 30 |  | 
|---|
| 31 | XSocketAddress::EError | 
|---|
| 32 | XSocketAddress::getError() const throw() | 
|---|
| 33 | { | 
|---|
| 34 | return m_error; | 
|---|
| 35 | } | 
|---|
| 36 |  | 
|---|
| 37 | CString | 
|---|
| 38 | XSocketAddress::getHostname() const throw() | 
|---|
| 39 | { | 
|---|
| 40 | return m_hostname; | 
|---|
| 41 | } | 
|---|
| 42 |  | 
|---|
| 43 | int | 
|---|
| 44 | XSocketAddress::getPort() const throw() | 
|---|
| 45 | { | 
|---|
| 46 | return m_port; | 
|---|
| 47 | } | 
|---|
| 48 |  | 
|---|
| 49 | CString | 
|---|
| 50 | XSocketAddress::getWhat() const throw() | 
|---|
| 51 | { | 
|---|
| 52 | static const char* s_errorID[] = { | 
|---|
| 53 | "XSocketAddressUnknown", | 
|---|
| 54 | "XSocketAddressNotFound", | 
|---|
| 55 | "XSocketAddressNoAddress", | 
|---|
| 56 | "XSocketAddressUnsupported", | 
|---|
| 57 | "XSocketAddressBadPort" | 
|---|
| 58 | }; | 
|---|
| 59 | static const char* s_errorMsg[] = { | 
|---|
| 60 | "unknown error for: %{1}:%{2}", | 
|---|
| 61 | "address not found for: %{1}", | 
|---|
| 62 | "no address for: %{1}", | 
|---|
| 63 | "unsupported address for: %{1}", | 
|---|
| 64 | "invalid port"                          // m_port may not be set to the bad port | 
|---|
| 65 | }; | 
|---|
| 66 | return format(s_errorID[m_error], s_errorMsg[m_error], | 
|---|
| 67 | m_hostname.c_str(), | 
|---|
| 68 | CStringUtil::print("%d", m_port).c_str()); | 
|---|
| 69 | } | 
|---|
| 70 |  | 
|---|
| 71 |  | 
|---|
| 72 | // | 
|---|
| 73 | // XSocketIOClose | 
|---|
| 74 | // | 
|---|
| 75 |  | 
|---|
| 76 | CString | 
|---|
| 77 | XSocketIOClose::getWhat() const throw() | 
|---|
| 78 | { | 
|---|
| 79 | return format("XSocketIOClose", "close: %{1}", what()); | 
|---|
| 80 | } | 
|---|
| 81 |  | 
|---|
| 82 |  | 
|---|
| 83 | // | 
|---|
| 84 | // XSocketBind | 
|---|
| 85 | // | 
|---|
| 86 |  | 
|---|
| 87 | CString | 
|---|
| 88 | XSocketBind::getWhat() const throw() | 
|---|
| 89 | { | 
|---|
| 90 | return format("XSocketBind", "cannot bind address: %{1}", what()); | 
|---|
| 91 | } | 
|---|
| 92 |  | 
|---|
| 93 |  | 
|---|
| 94 | // | 
|---|
| 95 | // XSocketConnect | 
|---|
| 96 | // | 
|---|
| 97 |  | 
|---|
| 98 | CString | 
|---|
| 99 | XSocketConnect::getWhat() const throw() | 
|---|
| 100 | { | 
|---|
| 101 | return format("XSocketConnect", "cannot connect socket: %{1}", what()); | 
|---|
| 102 | } | 
|---|
| 103 |  | 
|---|
| 104 |  | 
|---|
| 105 | // | 
|---|
| 106 | // XSocketCreate | 
|---|
| 107 | // | 
|---|
| 108 |  | 
|---|
| 109 | CString | 
|---|
| 110 | XSocketCreate::getWhat() const throw() | 
|---|
| 111 | { | 
|---|
| 112 | return format("XSocketCreate", "cannot create socket: %{1}", what()); | 
|---|
| 113 | } | 
|---|