[email protected] | 9257679 | 2013-09-20 15:29:13 | [diff] [blame] | 1 | // Copyright 2013 The Chromium Authors. All rights reserved. |
| 2 | // Use of this source code is governed by a BSD-style license that can be |
| 3 | // found in the LICENSE file. |
| 4 | |
| 5 | #ifndef PPAPI_SHARED_IMPL_PPB_TCP_SOCKET_SHARED_H_ |
| 6 | #define PPAPI_SHARED_IMPL_PPB_TCP_SOCKET_SHARED_H_ |
| 7 | |
| 8 | #include "ppapi/shared_impl/ppapi_shared_export.h" |
| 9 | |
| 10 | namespace ppapi { |
| 11 | |
| 12 | class PPAPI_SHARED_EXPORT TCPSocketState { |
| 13 | public: |
| 14 | enum StateType { |
| 15 | // The socket hasn't been bound or connected. |
| 16 | INITIAL, |
| 17 | // The socket has been bound. |
| 18 | BOUND, |
| 19 | // A connection has been established. |
| 20 | CONNECTED, |
| 21 | // An SSL connection has been established. |
| 22 | SSL_CONNECTED, |
| 23 | // The socket is listening. |
| 24 | LISTENING, |
| 25 | // The socket has been closed. |
| 26 | CLOSED |
| 27 | }; |
| 28 | |
| 29 | // Transitions that will change the socket state. Please note that |
| 30 | // read/write/accept are not included because they don't change the socket |
| 31 | // state. |
[email protected] | 665b5c54 | 2014-02-22 08:06:26 | [diff] [blame] | 32 | enum TransitionType { NONE, BIND, CONNECT, SSL_CONNECT, LISTEN, CLOSE }; |
[email protected] | 9257679 | 2013-09-20 15:29:13 | [diff] [blame] | 33 | |
| 34 | explicit TCPSocketState(StateType state); |
| 35 | ~TCPSocketState(); |
| 36 | |
| 37 | StateType state() const { return state_; } |
| 38 | |
| 39 | void SetPendingTransition(TransitionType pending_transition); |
| 40 | void CompletePendingTransition(bool success); |
| 41 | |
| 42 | void DoTransition(TransitionType transition, bool success); |
| 43 | |
| 44 | bool IsValidTransition(TransitionType transition) const; |
| 45 | bool IsPending(TransitionType transition) const; |
| 46 | |
| 47 | bool IsConnected() const; |
| 48 | bool IsBound() const; |
| 49 | |
| 50 | private: |
| 51 | StateType state_; |
| 52 | TransitionType pending_transition_; |
| 53 | }; |
| 54 | |
| 55 | // TCP socket API versions. |
benwells | e574178 | 2015-07-06 18:18:41 | [diff] [blame] | 56 | enum TCPSocketVersion { |
[email protected] | 9257679 | 2013-09-20 15:29:13 | [diff] [blame] | 57 | // PPB_TCPSocket_Private. |
| 58 | TCP_SOCKET_VERSION_PRIVATE, |
| 59 | // PPB_TCPSocket v1.0. |
| 60 | TCP_SOCKET_VERSION_1_0, |
| 61 | // PPB_TCPSocket v1.1 or above. |
| 62 | TCP_SOCKET_VERSION_1_1_OR_ABOVE |
| 63 | }; |
| 64 | |
| 65 | } // namespace ppapi |
| 66 | |
| 67 | #endif // PPAPI_SHARED_IMPL_PPB_TCP_SOCKET_SHARED_H_ |