Data Fields

PP_Resource(* Create )(PP_Instance instance)
PP_Bool(* IsTCPSocket )(PP_Resource resource)
int32_t(* Bind )(PP_Resource tcp_socket, PP_Resource addr, struct PP_CompletionCallback callback)
int32_t(* Connect )(PP_Resource tcp_socket, PP_Resource addr, struct PP_CompletionCallback callback)
PP_Resource(* GetLocalAddress )(PP_Resource tcp_socket)
PP_Resource(* GetRemoteAddress )(PP_Resource tcp_socket)
int32_t(* Read )(PP_Resource tcp_socket, char *buffer, int32_t bytes_to_read, struct PP_CompletionCallback callback)
int32_t(* Write )(PP_Resource tcp_socket, const char *buffer, int32_t bytes_to_write, struct PP_CompletionCallback callback)
int32_t(* Listen )(PP_Resource tcp_socket, int32_t backlog, struct PP_CompletionCallback callback)
int32_t(* Accept )(PP_Resource tcp_socket, PP_Resource *accepted_tcp_socket, struct PP_CompletionCallback callback)
void(* Close )(PP_Resource tcp_socket)
int32_t(* SetOption )(PP_Resource tcp_socket, PP_TCPSocket_Option name, struct PP_Var value, struct PP_CompletionCallback callback)

Detailed Description

The PPB_TCPSocket interface provides TCP socket operations.

Permissions: Apps permission socket with subrule tcp-connect is required for Connect(); subrule tcp-listen is required for Listen(). For more details about network communication permissions, please see: /apps/app_network.html


Field Documentation

int32_t(* PPB_TCPSocket::Accept)(PP_Resource tcp_socket, PP_Resource *accepted_tcp_socket, struct PP_CompletionCallback callback)

Accepts a connection.

The socket must be listening.

Parameters:
[in]tcp_socketA PP_Resource corresponding to a TCP socket.
[out]accepted_tcp_socketStores the accepted TCP socket on success.
[in]callbackA PP_CompletionCallback to be called upon completion.
Returns:
An int32_t containing an error code from pp_errors.h, including (but not limited to):
  • PP_ERROR_CONNECTION_ABORTED: A connection has been aborted.
int32_t(* PPB_TCPSocket::Bind)(PP_Resource tcp_socket, PP_Resource addr, struct PP_CompletionCallback callback)

Binds the socket to the given address.

The socket must not be bound.

Parameters:
[in]tcp_socketA PP_Resource corresponding to a TCP socket.
[in]addrA PPB_NetAddress resource.
[in]callbackA PP_CompletionCallback to be called upon completion.
Returns:
An int32_t containing an error code from pp_errors.h, including (but not limited to):
  • PP_ERROR_ADDRESS_IN_USE: the address is already in use.
  • PP_ERROR_ADDRESS_INVALID: the address is invalid.
void(* PPB_TCPSocket::Close)(PP_Resource tcp_socket)

Cancels all pending operations and closes the socket.

Any pending callbacks will still run, reporting PP_ERROR_ABORTED if pending IO was interrupted. After a call to this method, no output buffer pointers passed into previous Read() or Accept() calls will be accessed. It is not valid to call Connect() or Listen() again.

The socket is implicitly closed if it is destroyed, so you are not required to call this method.

Parameters:
[in]tcp_socketA PP_Resource corresponding to a TCP socket.
int32_t(* PPB_TCPSocket::Connect)(PP_Resource tcp_socket, PP_Resource addr, struct PP_CompletionCallback callback)

Connects the socket to the given address.

The socket must not be listening. Binding the socket beforehand is optional.

Parameters:
[in]tcp_socketA PP_Resource corresponding to a TCP socket.
[in]addrA PPB_NetAddress resource.
[in]callbackA PP_CompletionCallback to be called upon completion.
Returns:
An int32_t containing an error code from pp_errors.h, including (but not limited to):
  • PP_ERROR_NOACCESS: the caller doesn't have required permissions.
  • PP_ERROR_ADDRESS_UNREACHABLE: addr is unreachable.
  • PP_ERROR_CONNECTION_REFUSED: the connection attempt was refused.
  • PP_ERROR_CONNECTION_FAILED: the connection attempt failed.
  • PP_ERROR_CONNECTION_TIMEDOUT: the connection attempt timed out.

Since version 1.1, if the socket is listening/connected or has a pending listen/connect request, Connect() will fail without starting a connection attempt; otherwise, any failure during the connection attempt will cause the socket to be closed.

Creates a TCP socket resource.

Parameters:
[in]instanceA PP_Instance identifying one instance of a module.
Returns:
A PP_Resource corresponding to a TCP socket or 0 on failure.

Gets the local address of the socket, if it is bound.

Parameters:
[in]tcp_socketA PP_Resource corresponding to a TCP socket.
Returns:
A PPB_NetAddress resource on success or 0 on failure.

Gets the remote address of the socket, if it is connected.

Parameters:
[in]tcp_socketA PP_Resource corresponding to a TCP socket.
Returns:
A PPB_NetAddress resource on success or 0 on failure.

Determines if a given resource is a TCP socket.

Parameters:
[in]resourceA PP_Resource to check.
Returns:
PP_TRUE if the input is a PPB_TCPSocket resource; PP_FALSE otherwise.
int32_t(* PPB_TCPSocket::Listen)(PP_Resource tcp_socket, int32_t backlog, struct PP_CompletionCallback callback)

Starts listening.

The socket must be bound and not connected.

Parameters:
[in]tcp_socketA PP_Resource corresponding to a TCP socket.
[in]backlogA hint to determine the maximum length to which the queue of pending connections may grow.
[in]callbackA PP_CompletionCallback to be called upon completion.
Returns:
An int32_t containing an error code from pp_errors.h, including (but not limited to):
  • PP_ERROR_NOACCESS: the caller doesn't have required permissions.
  • PP_ERROR_ADDRESS_IN_USE: Another socket is already listening on the same port.
int32_t(* PPB_TCPSocket::Read)(PP_Resource tcp_socket, char *buffer, int32_t bytes_to_read, struct PP_CompletionCallback callback)

Reads data from the socket.

The socket must be connected. It may perform a partial read.

Parameters:
[in]tcp_socketA PP_Resource corresponding to a TCP socket.
[out]bufferThe buffer to store the received data on success. It must be at least as large as bytes_to_read.
[in]bytes_to_readThe number of bytes to read.
[in]callbackA PP_CompletionCallback to be called upon completion.
Returns:
A non-negative number on success to indicate how many bytes have been read, 0 means that end-of-file was reached; otherwise, an error code from pp_errors.h.
int32_t(* PPB_TCPSocket::SetOption)(PP_Resource tcp_socket, PP_TCPSocket_Option name, struct PP_Var value, struct PP_CompletionCallback callback)

Sets a socket option on the TCP socket.

Please see the PP_TCPSocket_Option description for option names, value types and allowed values.

Parameters:
[in]tcp_socketA PP_Resource corresponding to a TCP socket.
[in]nameThe option to set.
[in]valueThe option value to set.
[in]callbackA PP_CompletionCallback to be called upon completion.
Returns:
An int32_t containing an error code from pp_errors.h.
int32_t(* PPB_TCPSocket::Write)(PP_Resource tcp_socket, const char *buffer, int32_t bytes_to_write, struct PP_CompletionCallback callback)

Writes data to the socket.

The socket must be connected. It may perform a partial write.

Parameters:
[in]tcp_socketA PP_Resource corresponding to a TCP socket.
[in]bufferThe buffer containing the data to write.
[in]bytes_to_writeThe number of bytes to write.
[in]callbackA PP_CompletionCallback to be called upon completion.
Returns:
A non-negative number on success to indicate how many bytes have been written; otherwise, an error code from pp_errors.h.

The documentation for this struct was generated from the following file:
This site uses cookies to deliver and enhance the quality of its services and to analyze traffic. If you agree, cookies are also used to serve advertising and to personalize the content and advertisements that you see. Learn more about our use of cookies.