tcpjob.h
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2007 Tommi Maekitalo
3  *
4  * This library is free software; you can redistribute it and/or
5  * modify it under the terms of the GNU Lesser General Public
6  * License as published by the Free Software Foundation; either
7  * version 2.1 of the License, or (at your option) any later version.
8  *
9  * As a special exception, you may use this file as part of a free
10  * software library without restriction. Specifically, if other files
11  * instantiate templates or use macros or inline functions from this
12  * file, or you compile this file and link it with other files to
13  * produce an executable, this file does not by itself cause the
14  * resulting executable to be covered by the GNU General Public
15  * License. This exception does not however invalidate any other
16  * reasons why the executable file might be covered by the GNU Library
17  * General Public License.
18  *
19  * This library is distributed in the hope that it will be useful,
20  * but WITHOUT ANY WARRANTY; without even the implied warranty of
21  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
22  * Lesser General Public License for more details.
23  *
24  * You should have received a copy of the GNU Lesser General Public
25  * License along with this library; if not, write to the Free Software
26  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
27  */
28 
29 
30 #ifndef TNT_TCPJOB_H
31 #define TNT_TCPJOB_H
32 
33 #include <tnt/job.h>
34 #include <cxxtools/net/tcpstream.h>
35 #include <tnt/ssl.h>
36 #include <tnt/socketif.h>
37 #include <tnt/tntconfig.h>
38 
40 
41 namespace tnt
42 {
43  class Tcpjob : public Job, private SocketIf
44  {
46  const cxxtools::net::TcpServer& _listener;
47  Jobqueue& _queue;
48 
49  void accept();
50  void handshake();
51  void regenerateJob();
52 
53  virtual std::string getPeerIp() const;
54  virtual std::string getServerIp() const;
55  virtual bool isSsl() const;
56 
57  public:
58  Tcpjob(Tntnet& app, const cxxtools::net::TcpServer& listener, Jobqueue& queue)
59  : Job(app, this),
60  _socket(TntConfig::it().socketBufferSize, TntConfig::it().socketReadTimeout),
61  _listener(listener),
62  _queue(queue)
63  { }
64 
65  std::iostream& getStream();
66  int getFd() const;
67  void setRead();
68  void setWrite();
69  };
70 
71 #ifdef USE_SSL
72  class SslTcpjob : public Job, private SocketIf
73  {
74  ssl_iostream _socket;
75  const SslServer& _listener;
76  Jobqueue& _queue;
77 
78  void accept();
79  void handshake();
80  void regenerateJob();
81 
82  virtual std::string getPeerIp() const;
83  virtual std::string getServerIp() const;
84  virtual bool isSsl() const;
85 
86  public:
87  SslTcpjob(Tntnet& app, const SslServer& listener, Jobqueue& queue)
88  : Job(app, this),
89  _socket(TntConfig::it().socketBufferSize, TntConfig::it().socketReadTimeout),
90  _listener(listener),
91  _queue(queue)
92  { }
93 
94  std::iostream& getStream();
95  int getFd() const;
96  void setRead();
97  void setWrite();
98  };
99 #endif // USE_SSL
100 }
101 
102 #endif // TNT_TCPJOB_H
103