OFFIS DCMTK  Version 3.6.0
socket.h
Go to the documentation of this file.
1 // Module: Log4CPLUS
2 // File: socket.h
3 // Created: 4/2003
4 // Author: Tad E. Smith
5 //
6 //
7 // Copyright 2003-2009 Tad E. Smith
8 //
9 // Licensed under the Apache License, Version 2.0 (the "License");
10 // you may not use this file except in compliance with the License.
11 // You may obtain a copy of the License at
12 //
13 // http://www.apache.org/licenses/LICENSE-2.0
14 //
15 // Unless required by applicable law or agreed to in writing, software
16 // distributed under the License is distributed on an "AS IS" BASIS,
17 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
18 // See the License for the specific language governing permissions and
19 // limitations under the License.
20 
23 #ifndef LOG4CPLUS_HELPERS_SOCKET_HEADER_
24 #define LOG4CPLUS_HELPERS_SOCKET_HEADER_
25 
26 #include "dcmtk/oflog/config.h"
27 #include "dcmtk/oflog/tstring.h"
29 #if defined(_WIN32)
30 #include <winsock.h>
31 #endif
32 
33 namespace log4cplus {
34  namespace helpers {
35 
36  enum SocketState { ok,
37  not_opened,
38  bad_address,
39  connection_failed,
40  broken_pipe,
41  invalid_access_mode,
42  message_truncated
43  };
44 
45 #if !defined(_WIN32)
46  typedef int SOCKET_TYPE;
47 #define INVALID_SOCKET -1
48 #else
49  typedef SOCKET SOCKET_TYPE;
50 #endif
51 
52  class LOG4CPLUS_EXPORT AbstractSocket {
53  public:
54  // ctor and dtor
56  AbstractSocket(SOCKET_TYPE sock, SocketState state, int err);
58  virtual ~AbstractSocket() = 0;
59 
60  // methods
62  virtual void close();
63  virtual bool isOpen() const;
64 
65  AbstractSocket& operator=(const AbstractSocket& rhs);
66 
67  protected:
68  // Methods
69  virtual void copy(const AbstractSocket& rhs);
70 
71  // Data
72  SOCKET_TYPE sock;
73  SocketState state;
74  int err;
75  };
76 
77 
78 
83  class LOG4CPLUS_EXPORT Socket : public AbstractSocket {
84  public:
85  // ctor and dtor
86  Socket();
87  Socket(SOCKET_TYPE sock, SocketState state, int err);
88  Socket(const tstring& address, int port);
89  virtual ~Socket();
90 
91  // methods
92  virtual bool read(SocketBuffer& buffer);
93  virtual bool write(const SocketBuffer& buffer);
94  };
95 
96 
97 
104  class LOG4CPLUS_EXPORT ServerSocket : public AbstractSocket {
105  public:
106  // ctor and dtor
107  ServerSocket(int port);
108  virtual ~ServerSocket();
109 
110  Socket accept();
111  };
112 
113 
114  LOG4CPLUS_EXPORT SOCKET_TYPE openSocket(unsigned short port, SocketState& state);
115  LOG4CPLUS_EXPORT SOCKET_TYPE connectSocket(const log4cplus::tstring& hostn,
116  unsigned short port, SocketState& state);
117  LOG4CPLUS_EXPORT SOCKET_TYPE acceptSocket(SOCKET_TYPE sock, SocketState& state);
118  LOG4CPLUS_EXPORT int closeSocket(SOCKET_TYPE sock);
119 
120  LOG4CPLUS_EXPORT long read(SOCKET_TYPE sock, SocketBuffer& buffer);
121  LOG4CPLUS_EXPORT long write(SOCKET_TYPE sock, const SocketBuffer& buffer);
122 
123  LOG4CPLUS_EXPORT tstring getHostname (bool fqdn);
124 
125  } // end namespace helpers
126 } // end namespace log4cplus
127 
128 #endif // LOG4CPLUS_HELPERS_SOCKET_HEADER_


Generated on Thu Dec 20 2012 for OFFIS DCMTK Version 3.6.0 by Doxygen 1.8.2