thing-if SDK
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros
Data Structures | Typedefs | Enumerations
kii_socket_callback.h File Reference
#include <stddef.h>

Go to the source code of this file.

Data Structures

struct  kii_socket_context_t
 

Typedefs

typedef enum kii_http_error_t kii_http_error_t
 
typedef struct kii_socket_context_t kii_socket_context_t
 
typedef enum kii_socket_code_t kii_socket_code_t
 
typedef kii_socket_code_t(* KII_SOCKET_CONNECT_CB )(kii_socket_context_t *socket_context, const char *host, unsigned int port)
 
typedef kii_socket_code_t(* KII_SOCKET_SEND_CB )(kii_socket_context_t *socket_context, const char *buffer, size_t length)
 
typedef kii_socket_code_t(* KII_SOCKET_RECV_CB )(kii_socket_context_t *socket_context, char *buffer, size_t length_to_read, size_t *out_actual_length)
 
typedef kii_socket_code_t(* KII_SOCKET_CLOSE_CB )(kii_socket_context_t *socket_context)
 

Enumerations

enum  kii_http_error_t { KII_HTTP_ERROR_NONE, KII_HTTP_ERROR_INVALID_RESPONSE, KII_HTTP_ERROR_INSUFFICIENT_BUFFER, KII_HTTP_ERROR_SOCKET }
 
enum  kii_socket_code_t { KII_SOCKETC_OK, KII_SOCKETC_FAIL, KII_SOCKETC_AGAIN }
 

Typedef Documentation

typedef kii_socket_code_t(* KII_SOCKET_CLOSE_CB)(kii_socket_context_t *socket_context)

Callback for closing socket. Applications must implement this callback in the target enviroment.

Parameters
[in]socket_contextcontext object.
Returns
If applications succeed to close socket, applications need to return KII_SOCKETC_OK. If applications fail to close socket, applications need to return KII_SOCKETC_FAIL. If applications want to pend returning success or fail, applications need to return KII_SOCKETC_AGAIN.
typedef kii_socket_code_t(* KII_SOCKET_CONNECT_CB)(kii_socket_context_t *socket_context, const char *host, unsigned int port)

Callback for connecting socket to server. Applications must implement this callback in the target enviroment.

Parameters
[in]socket_contextcontext object.
[in]hosthost name.
[in]portport number.
Returns
If connection is succeeded, applications need to return KII_SOCKETC_OK. If connection is failed, applications need to return KII_SOCKETC_FAIL. If applications want to pend returning success or fail, applications need to return KII_SOCKETC_AGAIN.
typedef kii_socket_code_t(* KII_SOCKET_RECV_CB)(kii_socket_context_t *socket_context, char *buffer, size_t length_to_read, size_t *out_actual_length)

Callback for receiving data from server. Applications must implement this callback in the target enviroment.

Parameters
[in]socket_contextcontext object.
[out]bufferbuffer to set receiving data.
[in]length_to_readbuffer size.
[out]out_actual_lengthactual set data size.
Returns
If applications succeed to receive data and set the data to buffer, applications need to return KII_SOCKETC_OK. Applications also set data size to out_actual_length. If applications fail, applications need to return KII_HTTPC_FAIL. If applications want to wait to receive data, applications need to return KII_HTTPC_AGAIN. In this case, applications must not set receving data to buffer if some data is received.
typedef kii_socket_code_t(* KII_SOCKET_SEND_CB)(kii_socket_context_t *socket_context, const char *buffer, size_t length)

Callback for sending data to server. Applications must implement this callback in the target enviroment.

Parameters
[in]socket_contextcontext object.
[in]bufferdata to send server.
[in]lengthlength of buffer.
Returns
If applications succeed to send data, applications need to return KII_SOCKETC_OK. If connection is failed. applications need to return KII_SOCKETC__FAIL. If applications don't want to send data, applications need to return KII_SOCKETC_AGAIN. In this case, KiiThingSDK Embedded Core pass same data to this callback again.

Enumeration Type Documentation

Enumerator
KII_HTTP_ERROR_NONE 

No error.

KII_HTTP_ERROR_INVALID_RESPONSE 

Invalid response.

KII_HTTP_ERROR_INSUFFICIENT_BUFFER 

Response buffer overflow.

KII_HTTP_ERROR_SOCKET 

Socket functions returns false.

Enumerator
KII_SOCKETC_OK 

Retrun this code when operation succeed.

KII_SOCKETC_FAIL 

Return this code when operation failed.

KII_SOCKETC_AGAIN 

Return this code when operation is in progress.

SDK calls the callback again until the callbacks returns
KII_SOCKETC_OK or KII_SOCKETC_FAIL.