Shadow Network Framework  0.0.2-alpha
C Server Library for Shadow Network Framework
Loading...
Searching...
No Matches
network.h File Reference

This file Defines everything related to networking. More...

Go to the source code of this file.

Macros

#define SNF_Total_Data   (SNF_Total_Data_Rcv + SNF_Total_Data_Snt)
 Macro that defines the Total data tranferred so far.
 
#define UNIT_SCEPARATOR   "\x1F"
 Character that sceparates each argument (To be Removed)
 
#define snf_rcv(Client, Buffer, _Size)
 Same as snf_rcv_ how ever _Flags will be 0.
 
#define snf_rcv_PEEK(Client, Buffer, _Size)
 Same as snf_rcv_ how ever _Flags will be MSG_PEEK.
 

Functions

void snf_network_init ()
 Initializes the Network Framwork.
 
void snf_network_join ()
 See snf_thpool_join.
 
int snf_snd (SNF_CLT *Client, const char *Buffer, int _Size)
 Sends a Buffer to Client's socket's file descriptor.
 
int snf_rcv_ (SNF_CLT *Client, void *Buffer, int _Size, int _Flags)
 Receives a Buffer from Client's socket's file descriptor.
 

Variables

int SNF_SERVER_SOCKET
 the main Socket that accepts new incoming connections
 
struct sockaddr_in SNF_SERVER_ADDR
 Structure that saves the Server's sockaddr_in.
 
struct sockaddr_in SNF_CLIENT_ADDR
 Structure that saves the Client's sockaddr_in.
 
socklen_t SNF_CLIENT_LEN
 Used for accept's length argument.
 
_Atomic uint64_t SNF_Total_Data_Rcv
 Saves the Total data received so far.
 
_Atomic uint64_t SNF_Total_Data_Snt
 Saves the Total data sent so far.
 

Detailed Description

This file Defines everything related to networking.

Macro Definition Documentation

◆ SNF_Total_Data

#define SNF_Total_Data   (SNF_Total_Data_Rcv + SNF_Total_Data_Snt)

Macro that defines the Total data tranferred so far.

Warning
Innacurate for now

◆ UNIT_SCEPARATOR

#define UNIT_SCEPARATOR   "\x1F"

Character that sceparates each argument (To be Removed)

◆ snf_rcv

#define snf_rcv ( Client,
Buffer,
_Size )
Value:
snf_rcv_(Client, Buffer, _Size, 0)
int snf_rcv_(SNF_CLT *Client, void *Buffer, int _Size, int _Flags)
Receives a Buffer from Client's socket's file descriptor.

Same as snf_rcv_ how ever _Flags will be 0.

◆ snf_rcv_PEEK

#define snf_rcv_PEEK ( Client,
Buffer,
_Size )
Value:
snf_rcv_(Client, Buffer, _Size, MSG_PEEK)

Same as snf_rcv_ how ever _Flags will be MSG_PEEK.

Function Documentation

◆ snf_network_init()

void snf_network_init ( )
extern

Initializes the Network Framwork.

◆ snf_network_join()

void snf_network_join ( )
extern

See snf_thpool_join.

◆ snf_snd()

int snf_snd ( SNF_CLT * Client,
const char * Buffer,
int _Size )
extern

Sends a Buffer to Client's socket's file descriptor.

Parameters
ClientPointer to the Client's SNF_CLT instance
BufferBuffer to send
_SizeSize of the Buffer (See Note )
Returns
The following possible results:
  • -1 Client Could be NULL, or In case of an Error , Check errno and compare it to send's possible Errors, if errno == EPIPE then ignore it as it was already dealt with.
  • int The amount of data sent.
Note
The _Size parameter could react differently depeding on it's value
  • If _Size < 0 then it will assume the Buffer is a string and send 4 bytes indicating the size (See snf_uint32_to_bytes on how those 4 bytes are written ) and then send the buffer.
  • else it will send the Buffer and the length will be _Size

◆ snf_rcv_()

int snf_rcv_ ( SNF_CLT * Client,
void * Buffer,
int _Size,
int _Flags )
extern

Receives a Buffer from Client's socket's file descriptor.

Parameters
ClientPointer to the Client's SNF_CLT instance
BufferReceived Buffer
_SizeExpected Size
_FlagsFlags that will be passed to recv()
Returns
The following possible results:
  • -1 Client Could be NULL, or In case of an Error , Check errno and compare it to send's possible Errors, if errno == EPIPE then ignore it as it was already dealt with.
  • int The amount of data sent.
Warning
If you receive n amount of bytes and is lower than _Size , it will assume that recv has failed and will check errno, as it could disconnect the client in somecases and the function will return -1.
Note
There is are re-definitions of snf_recv_ and are:

Variable Documentation

◆ SNF_SERVER_SOCKET

int SNF_SERVER_SOCKET
extern

the main Socket that accepts new incoming connections

Warning
Do not modify it's contents unless you know what you're doing.

◆ SNF_SERVER_ADDR

struct sockaddr_in SNF_SERVER_ADDR
extern

Structure that saves the Server's sockaddr_in.

Warning
Do not modify it's contents unless you know what you're doing.

◆ SNF_CLIENT_ADDR

struct sockaddr_in SNF_CLIENT_ADDR
extern

Structure that saves the Client's sockaddr_in.

Warning
Do not modify it's contents unless you know what you're doing.

◆ SNF_CLIENT_LEN

socklen_t SNF_CLIENT_LEN
extern

Used for accept's length argument.

Warning
Do not modify it's contents unless you know what you're doing.

◆ SNF_Total_Data_Rcv

_Atomic uint64_t SNF_Total_Data_Rcv
extern

Saves the Total data received so far.

Warning
Innacurate for now

◆ SNF_Total_Data_Snt

_Atomic uint64_t SNF_Total_Data_Snt
extern

Saves the Total data sent so far.

Warning
Innacurate for now