OpenOCD
socket.c File Reference

Socket abstraction layer. More...

Include dependency graph for socket.c:

Go to the source code of this file.

Functions

JAYLINK_PRIV bool socket_bind (int sock, const struct sockaddr *address, size_t length)
 Bind an address to a socket. More...
 
JAYLINK_PRIV bool socket_close (int sock)
 Close a socket. More...
 
JAYLINK_PRIV bool socket_recv (int sock, void *buffer, size_t *length, int flags)
 Receive a message from a socket. More...
 
JAYLINK_PRIV bool socket_recvfrom (int sock, void *buffer, size_t *length, int flags, struct sockaddr *address, size_t *address_length)
 Receive a message from a socket. More...
 
JAYLINK_PRIV bool socket_send (int sock, const void *buffer, size_t *length, int flags)
 Send a message on a socket. More...
 
JAYLINK_PRIV bool socket_sendto (int sock, const void *buffer, size_t *length, int flags, const struct sockaddr *address, size_t address_length)
 Send a message on a socket. More...
 
JAYLINK_PRIV bool socket_set_option (int sock, int level, int option, const void *value, size_t length)
 Set an option on a socket. More...
 

Detailed Description

Socket abstraction layer.

Definition in file socket.c.

Function Documentation

◆ socket_bind()

JAYLINK_PRIV bool socket_bind ( int  sock,
const struct sockaddr *  address,
size_t  length 
)

Bind an address to a socket.

Parameters
[in]sockSocket descriptor.
[in]addressAddress to be bound to the socket.
[in]lengthLength of the structure pointed to by address in bytes.
Returns
Whether the address was successfully assigned to the socket.

Definition at line 69 of file socket.c.

Referenced by discovery_tcp_scan().

◆ socket_close()

JAYLINK_PRIV bool socket_close ( int  sock)

Close a socket.

Parameters
[in]sockSocket descriptor.
Returns
Whether the socket was successfully closed.

Definition at line 44 of file socket.c.

Referenced by discovery_tcp_scan(), and transport_tcp_open().

◆ socket_recv()

JAYLINK_PRIV bool socket_recv ( int  sock,
void *  buffer,
size_t *  length,
int  flags 
)

Receive a message from a socket.

Parameters
[in]sockSocket descriptor.
[out]bufferBuffer to store the received message on success. Its content is undefined on failure.
[in,out]lengthMaximum length of the message in bytes. On success, the value gets updated with the actual number of received bytes. The value is undefined on failure.
[in]flagsFlags to modify the function behaviour. Use bitwise OR to specify multiple flags.
Returns
Whether a message was successfully received.

Definition at line 132 of file socket.c.

Referenced by _recv().

◆ socket_recvfrom()

JAYLINK_PRIV bool socket_recvfrom ( int  sock,
void *  buffer,
size_t *  length,
int  flags,
struct sockaddr *  address,
size_t *  address_length 
)

Receive a message from a socket.

Parameters
[in]sockSocket descriptor.
[out]bufferBuffer to store the received message on success. Its content is undefined on failure.
[in,out]lengthMaximum length of the message in bytes. On success, the value gets updated with the actual number of received bytes. The value is undefined on failure.
[in]flagsFlags to modify the function behaviour. Use bitwise OR to specify multiple flags.
[out]addressStructure to store the source address of the message on success. Its content is undefined on failure. Can be NULL.
[in,out]address_lengthLength of the structure pointed to by address in bytes. On success, the value gets updated with the actual length of the structure. The value is undefined on failure. Should be NULL if address is NULL.
Returns
Whether a message was successfully received.

Definition at line 211 of file socket.c.

Referenced by discovery_tcp_scan().

◆ socket_send()

JAYLINK_PRIV bool socket_send ( int  sock,
const void *  buffer,
size_t *  length,
int  flags 
)

Send a message on a socket.

Parameters
[in]sockSocket descriptor.
[in]bufferBuffer of the message to be sent.
[in,out]lengthLength of the message in bytes. On success, the value gets updated with the actual number of bytes sent. The value is undefined on failure.
[in]flagsFlags to modify the function behaviour. Use bitwise OR to specify multiple flags.
Returns
Whether the message was sent successfully.

Definition at line 100 of file socket.c.

Referenced by _send().

◆ socket_sendto()

JAYLINK_PRIV bool socket_sendto ( int  sock,
const void *  buffer,
size_t *  length,
int  flags,
const struct sockaddr *  address,
size_t  address_length 
)

Send a message on a socket.

Parameters
[in]sockSocket descriptor.
[in]bufferBuffer to send message from.
[in,out]lengthNumber of bytes to send. On success, the value gets updated with the actual number of bytes sent. The value is undefined on failure.
[in]flagsFlags to modify the function behaviour. Use bitwise OR to specify multiple flags.
[in]addressDestination address of the message.
[in]address_lengthLength of the structure pointed to by address in bytes.
Returns
Whether the message was successfully sent.

Definition at line 168 of file socket.c.

Referenced by discovery_tcp_scan().

◆ socket_set_option()

JAYLINK_PRIV bool socket_set_option ( int  sock,
int  level,
int  option,
const void *  value,
size_t  length 
)

Set an option on a socket.

Parameters
[in]sockSocket descriptor.
[in]levelLevel at which the option is defined.
[in]optionOption to set the value for.
[in]valueBuffer of the value to be set.
[in]lengthLength of the value buffer in bytes.
Returns
Whether the option was set successfully.

Definition at line 250 of file socket.c.

Referenced by discovery_tcp_scan(), and set_socket_timeouts().