Skip to content

Commit

Permalink
Introduce PPB_TCPSocket_Dev.
Browse files Browse the repository at this point in the history
This change exposes the PPB_TCPSocket_Dev interface and makes it to share the same backend as PPB_TCPSocket_Private.

It doesn't include:
- apps permission check;
- TCP socket options that PPB_TCPSocket_Private doesn't support.
These will be implemented in separate CLs.

BUG=247225
TEST=newly added test_tcp_socket.{h,cc}.

Review URL: https://chromiumcodereview.appspot.com/16667002

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@206014 0039d316-1c4b-4281-b951-d872f2087c98
  • Loading branch information
yzshen@chromium.org committed Jun 13, 2013
1 parent b1c988b commit b1784f4
Show file tree
Hide file tree
Showing 37 changed files with 1,898 additions and 354 deletions.
30 changes: 30 additions & 0 deletions chrome/test/ppapi/ppapi_browsertest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -300,6 +300,36 @@ TEST_PPAPI_OUT_OF_PROCESS(BrowserFont)
TEST_PPAPI_IN_PROCESS(Buffer)
TEST_PPAPI_OUT_OF_PROCESS(Buffer)

// TCPSocket tests.
IN_PROC_BROWSER_TEST_F(OutOfProcessPPAPITest, TCPSocket) {
RunTestViaHTTP(
LIST_TEST(TCPSocket_Connect)
LIST_TEST(TCPSocket_ReadWrite)
LIST_TEST(TCPSocket_SetOption)
);
}
IN_PROC_BROWSER_TEST_F(PPAPINaClNewlibTest, TCPSocket) {
RunTestViaHTTP(
LIST_TEST(TCPSocket_Connect)
LIST_TEST(TCPSocket_ReadWrite)
LIST_TEST(TCPSocket_SetOption)
);
}
IN_PROC_BROWSER_TEST_F(PPAPINaClGLibcTest, MAYBE_GLIBC(TCPSocket)) {
RunTestViaHTTP(
LIST_TEST(TCPSocket_Connect)
LIST_TEST(TCPSocket_ReadWrite)
LIST_TEST(TCPSocket_SetOption)
);
}
IN_PROC_BROWSER_TEST_F(PPAPINaClPNaClTest, TCPSocket) {
RunTestViaHTTP(
LIST_TEST(TCPSocket_Connect)
LIST_TEST(TCPSocket_ReadWrite)
LIST_TEST(TCPSocket_SetOption)
);
}

TEST_PPAPI_OUT_OF_PROCESS_WITH_SSL_SERVER(TCPSocketPrivate)
TEST_PPAPI_IN_PROCESS_WITH_SSL_SERVER(TCPSocketPrivate)
TEST_PPAPI_NACL_WITH_SSL_SERVER(TCPSocketPrivate)
Expand Down
2 changes: 2 additions & 0 deletions content/ppapi_plugin/ppapi_thread.cc
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,8 @@ PpapiThread::PpapiThread(const CommandLine& command_line, bool is_broker)
// note that only those InterfaceProxy-based ones require registration.
AddRoute(ppapi::API_ID_PPB_TCPSERVERSOCKET_PRIVATE,
&dispatcher_message_listener_);
AddRoute(ppapi::API_ID_PPB_TCPSOCKET,
&dispatcher_message_listener_);
AddRoute(ppapi::API_ID_PPB_TCPSOCKET_PRIVATE,
&dispatcher_message_listener_);
AddRoute(ppapi::API_ID_PPB_UDPSOCKET_PRIVATE,
Expand Down
2 changes: 2 additions & 0 deletions native_client_sdk/src/build_tools/sdk_files.list
Original file line number Diff line number Diff line change
Expand Up @@ -283,6 +283,7 @@ include/ppapi/c/dev/ppb_opengles2ext_dev.h
include/ppapi/c/dev/ppb_printing_dev.h
include/ppapi/c/dev/ppb_resource_array_dev.h
include/ppapi/c/dev/ppb_scrollbar_dev.h
include/ppapi/c/dev/ppb_tcp_socket_dev.h
include/ppapi/c/dev/ppb_testing_dev.h
include/ppapi/c/dev/ppb_text_input_dev.h
include/ppapi/c/dev/ppb_trace_event_dev.h
Expand Down Expand Up @@ -385,6 +386,7 @@ include/ppapi/cpp/dev/resource_array_dev.h
include/ppapi/cpp/dev/scriptable_object_deprecated.h
include/ppapi/cpp/dev/scrollbar_dev.h
include/ppapi/cpp/dev/selection_dev.h
include/ppapi/cpp/dev/tcp_socket_dev.h
include/ppapi/cpp/dev/text_input_dev.h
include/ppapi/cpp/dev/truetype_font_dev.h
include/ppapi/cpp/dev/url_util_dev.h
Expand Down
115 changes: 115 additions & 0 deletions ppapi/api/dev/ppb_tcp_socket_dev.idl
Original file line number Diff line number Diff line change
@@ -0,0 +1,115 @@
/* Copyright 2013 The Chromium Authors. All rights reserved.
* Use of this source code is governed by a BSD-style license that can be
* found in the LICENSE file.
*/

/**
* This file defines the <code>PPB_TCPSocket_Dev</code> interface.
*/

[generate_thunk]

label Chrome {
M29 = 0.1
};

[assert_size(4)]
enum PP_TCPSocket_Option_Dev {
// Disables coalescing of small writes to make TCP segments, and instead
// deliver data immediately. Value type is PP_VARTYPE_BOOL.
PP_TCPSOCKET_OPTION_NO_DELAY = 0,

// Specifies the socket send buffer in bytes. Value's type should be
// PP_VARTYPE_INT32.
// Note: This is only treated as a hint for the browser to set the buffer
// size. Even if SetOption() reports that this option has been successfully
// set, the browser doesn't guarantee to conform to it.
PP_TCPSOCKET_OPTION_SEND_BUFFER_SIZE = 1,

// Specifies the socket receive buffer in bytes. Value's type should be
// PP_VARTYPE_INT32.
// Note: This is only treated as a hint for the browser to set the buffer
// size. Even if SetOption() reports that this option has been successfully
// set, the browser doesn't guarantee to conform to it.
PP_TCPSOCKET_OPTION_RECV_BUFFER_SIZE = 2
};

/**
* The <code>PPB_TCPSocket_Dev</code> interface provides TCP socket operations.
*/
interface PPB_TCPSocket_Dev {
/**
* Allocates a TCP socket resource.
*/
PP_Resource Create([in] PP_Instance instance);

/**
* Determines if a given resource is TCP socket.
*/
PP_Bool IsTCPSocket([in] PP_Resource resource);

/**
* Connects to an address given by |addr|, which is a PPB_NetAddress_Dev
* resource.
*/
int32_t Connect([in] PP_Resource tcp_socket,
[in] PP_Resource addr,
[in] PP_CompletionCallback callback);

/**
* Gets the local address of the socket, if it has been connected.
* Returns a PPB_NetAddress_Dev resource on success; returns 0 on failure.
*/
PP_Resource GetLocalAddress([in] PP_Resource tcp_socket);

/**
* Gets the remote address of the socket, if it has been connected.
* Returns a PPB_NetAddress_Dev resource on success; returns 0 on failure.
*/
PP_Resource GetRemoteAddress([in] PP_Resource tcp_socket);

/**
* Reads data from the socket. The size of |buffer| must be at least as large
* as |bytes_to_read|. May perform a partial read. Returns the number of bytes
* read or an error code. If the return value is 0, then it indicates that
* end-of-file was reached.
*
* Multiple outstanding read requests are not supported.
*/
int32_t Read([in] PP_Resource tcp_socket,
[out] str_t buffer,
[in] int32_t bytes_to_read,
[in] PP_CompletionCallback callback);

/**
* Writes data to the socket. May perform a partial write. Returns the number
* of bytes written or an error code.
*
* Multiple outstanding write requests are not supported.
*/
int32_t Write([in] PP_Resource tcp_socket,
[in] str_t buffer,
[in] int32_t bytes_to_write,
[in] PP_CompletionCallback callback);

/**
* Cancels any IO that may be pending, and disconnects the socket. Any pending
* callbacks will still run, reporting PP_ERROR_ABORTED if pending IO was
* interrupted. It is NOT valid to call Connect() again after a call to this
* method. Note: If the socket is destroyed when it is still connected, then
* it will be implicitly disconnected, so you are not required to call this
* method.
*/
void Close([in] PP_Resource tcp_socket);

/**
* Sets an option on |tcp_socket|. Supported |name| and |value| parameters
* are as described for PP_TCPSocketOption_Dev. |callback| will be
* invoked with PP_OK if setting the option succeeds, or an error code
* otherwise. The socket must be connected before SetOption is called.
*/
int32_t SetOption([in] PP_Resource tcp_socket,
[in] PP_TCPSocket_Option_Dev name,
[in] PP_Var value,
[in] PP_CompletionCallback callback);
};
136 changes: 136 additions & 0 deletions ppapi/c/dev/ppb_tcp_socket_dev.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,136 @@
/* Copyright 2013 The Chromium Authors. All rights reserved.
* Use of this source code is governed by a BSD-style license that can be
* found in the LICENSE file.
*/

/* From dev/ppb_tcp_socket_dev.idl modified Wed Jun 12 11:16:37 2013. */

#ifndef PPAPI_C_DEV_PPB_TCP_SOCKET_DEV_H_
#define PPAPI_C_DEV_PPB_TCP_SOCKET_DEV_H_

#include "ppapi/c/pp_bool.h"
#include "ppapi/c/pp_completion_callback.h"
#include "ppapi/c/pp_instance.h"
#include "ppapi/c/pp_macros.h"
#include "ppapi/c/pp_resource.h"
#include "ppapi/c/pp_stdint.h"
#include "ppapi/c/pp_var.h"

#define PPB_TCPSOCKET_DEV_INTERFACE_0_1 "PPB_TCPSocket(Dev);0.1"
#define PPB_TCPSOCKET_DEV_INTERFACE PPB_TCPSOCKET_DEV_INTERFACE_0_1

/**
* @file
* This file defines the <code>PPB_TCPSocket_Dev</code> interface.
*/


/**
* @addtogroup Enums
* @{
*/
typedef enum {
/* Disables coalescing of small writes to make TCP segments, and instead
* deliver data immediately. Value type is PP_VARTYPE_BOOL. */
PP_TCPSOCKET_OPTION_NO_DELAY = 0,
/* Specifies the socket send buffer in bytes. Value's type should be
* PP_VARTYPE_INT32.
* Note: This is only treated as a hint for the browser to set the buffer
* size. Even if SetOption() reports that this option has been successfully
* set, the browser doesn't guarantee to conform to it. */
PP_TCPSOCKET_OPTION_SEND_BUFFER_SIZE = 1,
/* Specifies the socket receive buffer in bytes. Value's type should be
* PP_VARTYPE_INT32.
* Note: This is only treated as a hint for the browser to set the buffer
* size. Even if SetOption() reports that this option has been successfully
* set, the browser doesn't guarantee to conform to it. */
PP_TCPSOCKET_OPTION_RECV_BUFFER_SIZE = 2
} PP_TCPSocket_Option_Dev;
PP_COMPILE_ASSERT_SIZE_IN_BYTES(PP_TCPSocket_Option_Dev, 4);
/**
* @}
*/

/**
* @addtogroup Interfaces
* @{
*/
/**
* The <code>PPB_TCPSocket_Dev</code> interface provides TCP socket operations.
*/
struct PPB_TCPSocket_Dev_0_1 {
/**
* Allocates a TCP socket resource.
*/
PP_Resource (*Create)(PP_Instance instance);
/**
* Determines if a given resource is TCP socket.
*/
PP_Bool (*IsTCPSocket)(PP_Resource resource);
/**
* Connects to an address given by |addr|, which is a PPB_NetAddress_Dev
* resource.
*/
int32_t (*Connect)(PP_Resource tcp_socket,
PP_Resource addr,
struct PP_CompletionCallback callback);
/**
* Gets the local address of the socket, if it has been connected.
* Returns a PPB_NetAddress_Dev resource on success; returns 0 on failure.
*/
PP_Resource (*GetLocalAddress)(PP_Resource tcp_socket);
/**
* Gets the remote address of the socket, if it has been connected.
* Returns a PPB_NetAddress_Dev resource on success; returns 0 on failure.
*/
PP_Resource (*GetRemoteAddress)(PP_Resource tcp_socket);
/**
* Reads data from the socket. The size of |buffer| must be at least as large
* as |bytes_to_read|. May perform a partial read. Returns the number of bytes
* read or an error code. If the return value is 0, then it indicates that
* end-of-file was reached.
*
* Multiple outstanding read requests are not supported.
*/
int32_t (*Read)(PP_Resource tcp_socket,
char* buffer,
int32_t bytes_to_read,
struct PP_CompletionCallback callback);
/**
* Writes data to the socket. May perform a partial write. Returns the number
* of bytes written or an error code.
*
* Multiple outstanding write requests are not supported.
*/
int32_t (*Write)(PP_Resource tcp_socket,
const char* buffer,
int32_t bytes_to_write,
struct PP_CompletionCallback callback);
/**
* Cancels any IO that may be pending, and disconnects the socket. Any pending
* callbacks will still run, reporting PP_ERROR_ABORTED if pending IO was
* interrupted. It is NOT valid to call Connect() again after a call to this
* method. Note: If the socket is destroyed when it is still connected, then
* it will be implicitly disconnected, so you are not required to call this
* method.
*/
void (*Close)(PP_Resource tcp_socket);
/**
* Sets an option on |tcp_socket|. Supported |name| and |value| parameters
* are as described for PP_TCPSocketOption_Dev. |callback| will be
* invoked with PP_OK if setting the option succeeds, or an error code
* otherwise. The socket must be connected before SetOption is called.
*/
int32_t (*SetOption)(PP_Resource tcp_socket,
PP_TCPSocket_Option_Dev name,
struct PP_Var value,
struct PP_CompletionCallback callback);
};

typedef struct PPB_TCPSocket_Dev_0_1 PPB_TCPSocket_Dev;
/**
* @}
*/

#endif /* PPAPI_C_DEV_PPB_TCP_SOCKET_DEV_H_ */

Loading

0 comments on commit b1784f4

Please sign in to comment.