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. 32 enum TransitionType { 33 NONE, 34 BIND, 35 CONNECT, 36 SSL_CONNECT, 37 LISTEN, 38 CLOSE 39 }; 40 41 explicit TCPSocketState(StateType state); 42 ~TCPSocketState(); 43 44 StateType state() const { return state_; } 45 46 void SetPendingTransition(TransitionType pending_transition); 47 void CompletePendingTransition(bool success); 48 49 void DoTransition(TransitionType transition, bool success); 50 51 bool IsValidTransition(TransitionType transition) const; 52 bool IsPending(TransitionType transition) const; 53 54 bool IsConnected() const; 55 bool IsBound() const; 56 57 private: 58 StateType state_; 59 TransitionType pending_transition_; 60 }; 61 62 // TCP socket API versions. 63 enum PPAPI_SHARED_EXPORT TCPSocketVersion { 64 // PPB_TCPSocket_Private. 65 TCP_SOCKET_VERSION_PRIVATE, 66 // PPB_TCPSocket v1.0. 67 TCP_SOCKET_VERSION_1_0, 68 // PPB_TCPSocket v1.1 or above. 69 TCP_SOCKET_VERSION_1_1_OR_ABOVE 70 }; 71 72 } // namespace ppapi 73 74 #endif // PPAPI_SHARED_IMPL_PPB_TCP_SOCKET_SHARED_H_ 75