1
// Copyright 2008 Google Inc. All Rights Reserved.
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
10
#ifndef TALK_BASE_MACASYNCSOCKET_H__
11
#define TALK_BASE_MACASYNCSOCKET_H__
13
#include <CoreFoundation/CoreFoundation.h>
15
#include "talk/base/asyncsocket.h"
19
class MacBaseSocketServer;
21
class MacAsyncSocket : public AsyncSocket {
23
MacAsyncSocket(MacBaseSocketServer* ss);
24
virtual ~MacAsyncSocket();
26
bool valid() const { return source_ != NULL; }
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);
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);
48
// For the MacBaseSocketServer to disable callbacks when process_io is false.
49
void EnableCallbacks();
50
void DisableCallbacks();
53
// Creates an async socket from an existing bsd socket
54
explicit MacAsyncSocket(MacBaseSocketServer* ss, int native_socket);
56
// Attaches the socket to the CFRunloop and sets the wrapped bsd socket
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);
64
// Callback for the underlying CFSocketRef.
65
static void MacAsyncSocketCallBack(CFSocketRef s,
66
CFSocketCallBackType callbackType,
71
MacBaseSocketServer* ss_;
74
CFRunLoopSourceRef source_;
75
int current_callbacks_;
80
DISALLOW_EVIL_CONSTRUCTORS(MacAsyncSocket);
83
} // namespace talk_base
85
#endif // TALK_BASE_MACASYNCSOCKET_H__