~ubuntu-branches/debian/experimental/kopete/experimental

« back to all changes in this revision

Viewing changes to protocols/jabber/libjingle/talk/base/macasyncsocket.h

  • Committer: Package Import Robot
  • Author(s): Maximiliano Curia
  • Date: 2015-02-24 11:32:57 UTC
  • mfrom: (1.1.41 vivid)
  • Revision ID: package-import@ubuntu.com-20150224113257-gnupg4v7lzz18ij0
Tags: 4:14.12.2-1
* New upstream release (14.12.2).
* Bump Standards-Version to 3.9.6, no changes needed.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
// Copyright 2008 Google Inc. All Rights Reserved.
 
2
 
 
3
//
 
4
// MacAsyncSocket is a kind of AsyncSocket. It only creates sockets
 
5
// of the TCP type, and does not (yet) support listen and accept. It works
 
6
// asynchronously, which means that users of this socket should connect to
 
7
// the various events declared in asyncsocket.h to receive notifications about
 
8
// this socket.
 
9
 
 
10
#ifndef TALK_BASE_MACASYNCSOCKET_H__
 
11
#define TALK_BASE_MACASYNCSOCKET_H__
 
12
 
 
13
#include <CoreFoundation/CoreFoundation.h>
 
14
 
 
15
#include "talk/base/asyncsocket.h"
 
16
 
 
17
namespace talk_base {
 
18
 
 
19
class MacBaseSocketServer;
 
20
 
 
21
class MacAsyncSocket : public AsyncSocket {
 
22
 public:
 
23
  MacAsyncSocket(MacBaseSocketServer* ss);
 
24
  virtual ~MacAsyncSocket();
 
25
 
 
26
  bool valid() const { return source_ != NULL; }
 
27
 
 
28
  // Socket interface
 
29
  virtual SocketAddress GetLocalAddress() const;
 
30
  virtual SocketAddress GetRemoteAddress() const;
 
31
  virtual int Bind(const SocketAddress& addr);
 
32
  virtual int Connect(const SocketAddress& addr);
 
33
  virtual int Send(const void* buffer, size_t length);
 
34
  virtual int SendTo(const void* buffer, size_t length,
 
35
                     const SocketAddress& addr);
 
36
  virtual int Recv(void* buffer, size_t length);
 
37
  virtual int RecvFrom(void* buffer, size_t length, SocketAddress* out_addr);
 
38
  virtual int Listen(int backlog);
 
39
  virtual MacAsyncSocket* Accept(SocketAddress* out_addr);
 
40
  virtual int Close();
 
41
  virtual int GetError() const;
 
42
  virtual void SetError(int error);
 
43
  virtual ConnState GetState() const;
 
44
  virtual int EstimateMTU(uint16* mtu);
 
45
  virtual int GetOption(Option opt, int* value);
 
46
  virtual int SetOption(Option opt, int value);
 
47
 
 
48
  // For the MacBaseSocketServer to disable callbacks when process_io is false.
 
49
  void EnableCallbacks();
 
50
  void DisableCallbacks();
 
51
 
 
52
 private:
 
53
  // Creates an async socket from an existing bsd socket
 
54
  explicit MacAsyncSocket(MacBaseSocketServer* ss, int native_socket);
 
55
 
 
56
   // Attaches the socket to the CFRunloop and sets the wrapped bsd socket
 
57
  // to async mode
 
58
  void Initialize();
 
59
 
 
60
  // Translate the SocketAddress into a CFDataRef to pass to CF socket
 
61
  // functions. Caller must call CFRelease on the result when done.
 
62
  static CFDataRef CopyCFAddress(const SocketAddress& address);
 
63
 
 
64
  // Callback for the underlying CFSocketRef.
 
65
  static void MacAsyncSocketCallBack(CFSocketRef s,
 
66
                                     CFSocketCallBackType callbackType,
 
67
                                     CFDataRef address,
 
68
                                     const void* data,
 
69
                                     void* info);
 
70
 
 
71
  MacBaseSocketServer* ss_;
 
72
  CFSocketRef socket_;
 
73
  int native_socket_;
 
74
  CFRunLoopSourceRef source_;
 
75
  int current_callbacks_;
 
76
  bool disabled_;
 
77
  int error_;
 
78
  ConnState state_;
 
79
 
 
80
  DISALLOW_EVIL_CONSTRUCTORS(MacAsyncSocket);
 
81
};
 
82
 
 
83
}  // namespace talk_base
 
84
 
 
85
#endif  // TALK_BASE_MACASYNCSOCKET_H__