MIP_SDK  latest-2-g34f3e39
MicroStrain Communications Library for embedded systems
tcp_socket.h
Go to the documentation of this file.
1 #pragma once
2 
4 
5 #ifdef MICROSTRAIN_PLATFORM_WINDOWS
6 
7 #ifndef WIN32_LEAN_AND_MEAN
8 #define WIN32_LEAN_AND_MEAN
9 #endif
10 
11 #include <winsock2.h>
12 
13 #endif
14 
15 #include <stdint.h>
16 #include <stddef.h>
17 #include <stdbool.h>
18 
19 #ifdef __cplusplus
20 extern "C" {
21 #endif
22 
27 
34 
35 typedef struct tcp_socket
36 {
37 #ifdef MICROSTRAIN_PLATFORM_WINDOWS
38  SOCKET handle;
39 #else
40  int handle;
41 #endif
42 } tcp_socket;
43 
44 
45 
46 void tcp_socket_init(tcp_socket* socket_ptr);
47 bool tcp_socket_is_open(const tcp_socket* socket_ptr);
48 bool tcp_socket_open(tcp_socket* socket_ptr, const char* hostname, uint16_t port, unsigned int timeout_ms);
49 bool tcp_socket_close(tcp_socket* socket_ptr);
50 bool tcp_socket_send(tcp_socket* socket_ptr, const void* buffer, size_t num_bytes, size_t* bytes_written);
51 bool tcp_socket_recv(tcp_socket* socket_ptr, void* buffer, size_t num_bytes, size_t* bytes_read);
52 
56 
57 #ifdef __cplusplus
58 }
59 #endif
tcp_socket_send
bool tcp_socket_send(tcp_socket *socket_ptr, const void *buffer, size_t num_bytes, size_t *bytes_written)
Definition: tcp_socket.c:140
tcp_socket_recv
bool tcp_socket_recv(tcp_socket *socket_ptr, void *buffer, size_t num_bytes, size_t *bytes_read)
Definition: tcp_socket.c:153
tcp_socket
struct tcp_socket tcp_socket
tcp_socket::handle
int handle
Definition: tcp_socket.h:40
tcp_socket_open
bool tcp_socket_open(tcp_socket *socket_ptr, const char *hostname, uint16_t port, unsigned int timeout_ms)
Definition: tcp_socket.c:105
tcp_socket
Definition: tcp_socket.h:35
platform.h
tcp_socket_init
void tcp_socket_init(tcp_socket *socket_ptr)
Definition: tcp_socket.c:33
tcp_socket_close
bool tcp_socket_close(tcp_socket *socket_ptr)
Definition: tcp_socket.c:124
tcp_socket_is_open
bool tcp_socket_is_open(const tcp_socket *socket_ptr)
Definition: tcp_socket.c:38