/* * Copyright 2004 The WebRTC Project Authors. All rights reserved. * * Use of this source code is governed by a BSD-style license * that can be found in the LICENSE file in the root of the source * tree. An additional intellectual property rights grant can be found * in the file PATENTS. All contributing project authors may * be found in the AUTHORS file in the root of the source tree.
*/
inlinebool IsBlockingError(int e) { return (e == EWOULDBLOCK) || (e == EAGAIN) || (e == EINPROGRESS);
}
// General interface for the socket implementations of various networks. The // methods match those of normal UNIX sockets very closely. class RTC_EXPORT Socket { public: struct ReceiveBuffer {
ReceiveBuffer(Buffer& payload) : payload(payload) {}
// Returns the address to which the socket is bound. If the socket is not // bound, then the any-address is returned. virtual SocketAddress GetLocalAddress() const = 0;
// Returns the address to which the socket is connected. If the socket is // not connected, then the any-address is returned. virtual SocketAddress GetRemoteAddress() const = 0;
virtualint Bind(const SocketAddress& addr) = 0; virtualint Connect(const SocketAddress& addr) = 0; virtualint Send(constvoid* pv, size_t cb) = 0; virtualint SendTo(constvoid* pv, size_t cb, const SocketAddress& addr) = 0; // `timestamp` is in units of microseconds. virtualint Recv(void* pv, size_t cb, int64_t* timestamp) = 0; // TODO(webrtc:15368): Deprecate and remove. virtualint RecvFrom(void* /* pv */,
size_t /* cb */,
SocketAddress* /* paddr */,
int64_t* /* timestamp */) { // Not implemented. Use RecvFrom(ReceiveBuffer& buffer).
RTC_CHECK_NOTREACHED();
} // Intended to replace RecvFrom(void* ...). // Default implementation calls RecvFrom(void* ...) with 64Kbyte buffer. // Returns number of bytes received or a negative value on error. virtualint RecvFrom(ReceiveBuffer& buffer); virtualint Listen(int backlog) = 0; virtual Socket* Accept(SocketAddress* paddr) = 0; virtualint Close() = 0; virtualint GetError() const = 0; virtualvoid SetError(int error) = 0; inlinebool IsBlocking() const { return IsBlockingError(GetError()); }
enum Option {
OPT_DONTFRAGMENT,
OPT_RCVBUF, // receive buffer size
OPT_SNDBUF, // send buffer size
OPT_NODELAY, // whether Nagle algorithm is enabled
OPT_IPV6_V6ONLY, // Whether the socket is IPv6 only.
OPT_DSCP, // DSCP code
OPT_RTP_SENDTIME_EXTN_ID, // This is a non-traditional socket option param. // This is specific to libjingle and will be used // if SendTime option is needed at socket level.
OPT_SEND_ECN, // 2-bit ECN
OPT_RECV_ECN,
OPT_KEEPALIVE, // Enable socket keep alive
OPT_TCP_KEEPCNT, // Set TCP keep alive count
OPT_TCP_KEEPIDLE, // Set TCP keep alive idle time in seconds
OPT_TCP_KEEPINTVL, // Set TCP keep alive interval in seconds
OPT_TCP_USER_TIMEOUT, // Set TCP user timeout
}; virtualint GetOption(Option opt, int* value) = 0; virtualint SetOption(Option opt, int value) = 0;
// SignalReadEvent and SignalWriteEvent use multi_threaded_local to allow // access concurrently from different thread. // For example SignalReadEvent::connect will be called in AsyncUDPSocket ctor // but at the same time the SocketDispatcher may be signaling the read event. // ready to read
sigslot::signal1<Socket*, sigslot::multi_threaded_local> SignalReadEvent; // ready to write
sigslot::signal1<Socket*, sigslot::multi_threaded_local> SignalWriteEvent;
sigslot::signal1<Socket*> SignalConnectEvent; // connected
sigslot::signal2<Socket*, int> SignalCloseEvent; // closed
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.