NetIO.h
Go to the documentation of this file.
1 
8 #pragma once
9 // LIBOS LICENCE
10 //
11 // GNU Lesser General Public License Version 3.0
12 //
13 // Copyright Luke Shore (c) 2022, 2023
15 #include <libos/Defines.h>
20 typedef struct losSocket_T *losSocket;
24 typedef enum losSocketBit : uint8_t
25 {
26  LOS_SOCKET_UDP = 0x001,
27  LOS_SOCKET_TCP = 0x002,
28  LOS_SOCKET_APF = 0x004,
35 typedef struct losCreateSocketInfo
36 {
37  uint8_t socket_bits = 0;
38  const char *address;
40  size_t address_size = 0;
41  uint16_t port = 0;
43 
47 typedef struct losUdpData
48 {
50  void *data;
59 EXPORT_DLL uint32_t *losNetworkBytesToSystemBytes(_in_ const uint32_t *bytes, _in_ const size_t bytes_size);
67 EXPORT_DLL uint32_t *losSystemBytesToNetworkBytes(_in_ const uint32_t *bytes, _in_ const size_t bytes_size);
75 EXPORT_DLL int32_t *losNetworkBytesToSystemBytesSigned(_in_ const int32_t *bytes, _in_ const size_t bytes_size);
83 EXPORT_DLL int32_t *losSystemBytesToNetworkBytesSigned(_in_ const int32_t *bytes, _in_ const size_t bytes_size);
99 EXPORT_DLL losResult losReadSocket(_in_ const losSocket handle, _out_ void *buffer, _in_ const size_t bytes_to_read);
116 EXPORT_DLL losResult losWriteSocket(_in_ const losSocket handle, _in_ const void *buffer,
117  _in_ const size_t buffer_size);
losResult
losResult enum is used to indicate the result of a LibOS function call that can fail instead of throw...
Definition: DataType.h:47
defines hold function & macros for the parts of the library to work
#define _out_
out macromatic suger to make headers easier to read
Definition: Defines.h:44
#define EXPORT_DLL
on windows some extra syntax is required for the dll to work properly so that is dose not affect the ...
Definition: Defines.h:33
#define _in_
in macromatic suger to make headers easier to read
Definition: Defines.h:40
EXPORT_DLL losResult losDestroySocket(_in_ losSocket handle)
losDestroySocket is to close the library object and safely delete it
EXPORT_DLL losResult losWriteSocket(_in_ const losSocket handle, _in_ const void *buffer, _in_ const size_t buffer_size)
losWriteSocket write data to native socket held by the library object (NOTE: for server side udp it i...
struct losSocket_T * losSocket
this is the Library object that is used to read and write network data to and from the Native Socket ...
Definition: NetIO.h:20
EXPORT_DLL losResult losReadSocket(_in_ const losSocket handle, _out_ void *buffer, _in_ const size_t bytes_to_read)
losReadSocket read data from native socket held by the library object (NOTE: for server side udp it i...
EXPORT_DLL uint32_t * losSystemBytesToNetworkBytes(_in_ const uint32_t *bytes, _in_ const size_t bytes_size)
losSystemBytesToNetworkBytes converts from little-endian to big-endian(for now as we have not got an ...
EXPORT_DLL int32_t * losSystemBytesToNetworkBytesSigned(_in_ const int32_t *bytes, _in_ const size_t bytes_size)
losSystemBytesToNetworkBytesSigned converts signed from little-endian to big-endian(for now as we hav...
EXPORT_DLL uint32_t * losNetworkBytesToSystemBytes(_in_ const uint32_t *bytes, _in_ const size_t bytes_size)
losNetworkBytesToSystemBytes converts from big-endian to little-endian(for now as we have not got an ...
EXPORT_DLL int32_t * losNetworkBytesToSystemBytesSigned(_in_ const int32_t *bytes, _in_ const size_t bytes_size)
losNetworkBytesToSystemBytesSigned converts signed from big-endian to little-endian(for now as we hav...
EXPORT_DLL losResult losCreateSocket(_out_ losSocket *handle, _in_ const losCreateSocketInfo &socket_info)
losCreateSocket is to create the library object but dose not release the object to the library user
struct losUdpData losUdpData
simple wrapper used to handle UDP data on the server side
struct losCreateSocketInfo losCreateSocketInfo
losCreateSocketInfo is the socket creation struct we pass this into the creation function for the lib...
EXPORT_DLL losResult losWaitForClient(_in_ const losSocket handle, _out_ losSocket *new_client)
losWaitForClient is for server side TCP connection only we use this to wait for client connections an...
losSocketBit
losSocketBit is used for socket object flags
Definition: NetIO.h:25
@ LOS_SOCKET_SERVER
this is to tell the library that the socket is to be used as a server
Definition: NetIO.h:29
@ LOS_SOCKET_APF
this is for automatically port forwarding in the router flag bit (NOT_IMPLEMENTED)
Definition: NetIO.h:28
@ LOS_SOCKET_UDP
set socket to UDP socket flag bit
Definition: NetIO.h:26
@ LOS_SOCKET_TCP
set socket to TCP socket flag bit
Definition: NetIO.h:27
losCreateSocketInfo is the socket creation struct we pass this into the creation function for the lib...
Definition: NetIO.h:36
uint16_t port
this is to tell the library what port to use for the socket
Definition: NetIO.h:41
size_t address_size
size of string of address
Definition: NetIO.h:40
uint8_t socket_bits
socket (bits/flags) combination tells the library how to handle the socket
Definition: NetIO.h:37
const char * address
this is used to represent the address for where the socket is to bind or connect to based on if is cl...
Definition: NetIO.h:38
simple wrapper used to handle UDP data on the server side
Definition: NetIO.h:48
losSocket client
client socket
Definition: NetIO.h:49
void * data
data buffer to receive or send
Definition: NetIO.h:50