2 * Copyright (c) 2010 The Native Client Authors. All rights reserved.
3 * Use of this source code is governed by a BSD-style license that can be
4 * found in the LICENSE file.
8 // This module provides interfaces for an IO stream. The stream is
9 // expected to throw a std::exception if the stream is terminated on
11 #ifndef NATIVE_CLIENT_PORT_TRANSPORT_H_
12 #define NATIVE_CLIENT_PORT_TRANSPORT_H_
14 #include "native_client/src/include/portability.h"
15 #include "native_client/src/include/portability_sockets.h"
23 virtual ~ITransport() {} // Allow to delete using base pointer
25 // Read from this transport, return true on success.
26 virtual bool Read(void *ptr, int32_t len) = 0;
28 // Write to this transport, return true on success.
29 virtual bool Write(const void *ptr, int32_t len) = 0;
31 // Return true if there is data to read.
32 virtual bool IsDataAvailable() = 0;
34 // Wait until there is input from GDB or some NaCl thread is faulted.
35 virtual void WaitForDebugStubEvent(struct NaClApp *nap,
38 // Disconnect the transport, R/W and Select will now throw an exception
39 virtual void Disconnect() = 0;
44 // Wrap existing socket handle.
45 explicit SocketBinding(NaClSocketHandle socket_handle);
46 // Bind to the specified TCP port.
47 static SocketBinding *Bind(const char *addr);
49 // Accept a connection on an already-bound TCP port.
50 ITransport *AcceptConnection();
52 // Get port the socket is bound to.
53 uint16_t GetBoundPort();
56 NaClSocketHandle socket_handle_;
61 #endif // NATIVE_CLIENT_PORT_TRANSPORT_H_