63 lines
1.6 KiB
C
63 lines
1.6 KiB
C
#ifndef _DATASERVER_CLIENT_H_
|
|
#define _DATASERVER_CLIENT_H_
|
|
|
|
#include <stddef.h>
|
|
#include <stdint.h>
|
|
|
|
#ifdef __cplusplus
|
|
extern "C" {
|
|
#endif
|
|
|
|
struct ds_conn_s;
|
|
|
|
typedef struct ds_conn_s ds_conn_t;
|
|
|
|
#define VALID_DS_CONN(_conn_) ((_conn_) != NULL)
|
|
|
|
/**Open a connection to server
|
|
* Do not forget to destroy() after disconnec()
|
|
* \return the connection handle
|
|
*/
|
|
ds_conn_t* dataserver_connect(void);
|
|
ds_conn_t* dataserver_connect_ip(uint32_t addr, uint32_t port);
|
|
|
|
/**Read data from server with the connection handle
|
|
* \param connection the connection handle
|
|
* \param [out] buf the data will be filled in the buf
|
|
* \param size the size of the buf
|
|
* \param timeout_ms timeout in millisecond
|
|
* \retval <0 Error
|
|
* \return the size of the data that be filled in the buf
|
|
*/
|
|
int dataserver_read_message(ds_conn_t *connection, void *buf, size_t size, int timeout_ms);
|
|
|
|
/**Write data to server with the connection handle
|
|
* \param connection connection handle
|
|
* \param [out] buf the data to be written
|
|
* \param size the size of the data to be written
|
|
* \return <0 Error
|
|
* \return the size of data that have been written
|
|
*/
|
|
int dataserver_write_message(ds_conn_t *connection, void *buf, size_t size);
|
|
|
|
/**Close a connection to server, break the read_message()
|
|
* \param connection the connection handle
|
|
* \retval 0 OK
|
|
* \retval <0 Error
|
|
*/
|
|
int dataserver_disconnect(ds_conn_t *connection);
|
|
|
|
/**Destroy the connection
|
|
* \param connection the connection handle
|
|
* \retval 0 OK
|
|
* \retval <0 Error
|
|
*/
|
|
int dataserver_destroy(ds_conn_t *connection);
|
|
|
|
|
|
#ifdef __cplusplus
|
|
}
|
|
#endif
|
|
|
|
#endif
|