~ari-tczew/ubuntu/natty/clementine/lp-747113

« back to all changes in this revision

Viewing changes to 3rdparty/gloox/connectiontcpbase.h

  • Committer: Artur Rona
  • Date: 2011-04-04 20:05:33 UTC
  • Revision ID: ari-tczew@ubuntu.com-20110404200533-6aclzasj5pp8t1hq
* New upstream release. (LP: #747113)
* Drop all patches, have been applied upstream.
* Update debian/copyright.
* Refresh description in debian/control in order to avoid lintian error.
* Bump debhelper to 8.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
  Copyright (c) 2004-2009 by Jakob Schroeter <js@camaya.net>
 
3
  This file is part of the gloox library. http://camaya.net/gloox
 
4
 
 
5
  This software is distributed under a license. The full license
 
6
  agreement can be found in the file LICENSE in this distribution.
 
7
  This software may not be copied, modified, sold or distributed
 
8
  other than expressed in the named license agreement.
 
9
 
 
10
  This software is distributed without any warranty.
 
11
*/
 
12
 
 
13
 
 
14
#ifndef CONNECTIONTCPBASE_H__
 
15
#define CONNECTIONTCPBASE_H__
 
16
 
 
17
#include "gloox.h"
 
18
#include "connectionbase.h"
 
19
#include "logsink.h"
 
20
#include "mutex.h"
 
21
 
 
22
#include <string>
 
23
 
 
24
namespace gloox
 
25
{
 
26
 
 
27
  namespace util
 
28
  {
 
29
    class Mutex;
 
30
  }
 
31
 
 
32
  /**
 
33
   * @brief This is a base class for a simple TCP connection.
 
34
   *
 
35
   * You should not need to use this class directly.
 
36
   *
 
37
   * @author Jakob Schroeter <js@camaya.net>
 
38
   * @since 0.9
 
39
   */
 
40
  class GLOOX_API ConnectionTCPBase : public ConnectionBase
 
41
  {
 
42
    public:
 
43
      /**
 
44
       * Constructs a new ConnectionTCPBase object.
 
45
       * @param logInstance The log target. Obtain it from ClientBase::logInstance().
 
46
       * @param server A server to connect to.
 
47
       * @param port The port to connect to. The default of -1 means that XMPP SRV records
 
48
       * will be used to find out about the actual host:port.
 
49
       * @note To properly use this object, you have to set a ConnectionDataHandler using
 
50
       * registerConnectionDataHandler(). This is not necessary if this object is
 
51
       * part of a 'connection chain', e.g. with ConnectionHTTPProxy.
 
52
       */
 
53
      ConnectionTCPBase( const LogSink& logInstance, const std::string& server, int port = -1 );
 
54
 
 
55
      /**
 
56
       * Constructs a new ConnectionTCPBase object.
 
57
       * @param cdh An ConnectionDataHandler-derived object that will handle incoming data.
 
58
       * @param logInstance The log target. Obtain it from ClientBase::logInstance().
 
59
       * @param server A server to connect to.
 
60
       * @param port The port to connect to. The default of -1 means that SRV records will be used
 
61
       * to find out about the actual host:port.
 
62
       */
 
63
      ConnectionTCPBase( ConnectionDataHandler* cdh, const LogSink& logInstance,
 
64
                         const std::string& server, int port = -1 );
 
65
 
 
66
      /**
 
67
       * Virtual destructor
 
68
       */
 
69
      virtual ~ConnectionTCPBase();
 
70
 
 
71
      // reimplemented from ConnectionBase
 
72
      virtual bool send( const std::string& data );
 
73
 
 
74
      // reimplemented from ConnectionBase
 
75
      virtual ConnectionError receive();
 
76
 
 
77
      // reimplemented from ConnectionBase
 
78
      virtual void disconnect();
 
79
 
 
80
      // reimplemented from ConnectionBase
 
81
      virtual void cleanup();
 
82
 
 
83
      // reimplemented from ConnectionBase
 
84
      virtual void getStatistics( long int &totalIn, long int &totalOut );
 
85
 
 
86
      /**
 
87
       * Gives access to the raw socket of this connection. Use it wisely. You can
 
88
       * select()/poll() it and use ConnectionTCPBase::recv( -1 ) to fetch the data.
 
89
       * @return The socket of the active connection, or -1 if no connection is established.
 
90
       */
 
91
      int socket() const { return m_socket; }
 
92
 
 
93
      /**
 
94
       * This function allows to set an existing socket with an established
 
95
       * connection to use in this connection. You will still need to call connect() in order to
 
96
       * negotiate the XMPP stream. You should not set a new socket after having called connect().
 
97
       * @param socket The existing socket.
 
98
       */
 
99
      void setSocket( int socket ) { m_cancel = false; m_state = StateConnected; m_socket = socket; }
 
100
 
 
101
      /**
 
102
       * Returns the local port.
 
103
       * @return The local port.
 
104
       */
 
105
      virtual int localPort() const;
 
106
 
 
107
      /**
 
108
       * Returns the locally bound IP address.
 
109
       * @return The locally bound IP address.
 
110
       */
 
111
      virtual const std::string localInterface() const;
 
112
 
 
113
    protected:
 
114
      ConnectionTCPBase& operator=( const ConnectionTCPBase& );
 
115
      void init( const std::string& server, int port );
 
116
      bool dataAvailable( int timeout = -1 );
 
117
      void cancel();
 
118
 
 
119
      const LogSink& m_logInstance;
 
120
      util::Mutex m_sendMutex;
 
121
      util::Mutex m_recvMutex;
 
122
 
 
123
      char* m_buf;
 
124
      int m_socket;
 
125
      long int m_totalBytesIn;
 
126
      long int m_totalBytesOut;
 
127
      const int m_bufsize;
 
128
      bool m_cancel;
 
129
 
 
130
  };
 
131
 
 
132
}
 
133
 
 
134
#endif // CONNECTIONTCPBASE_H__