Shadow Network Framework  0.0.2-alpha
C Server Library for Shadow Network Framework
Loading...
Searching...
No Matches
network.h
Go to the documentation of this file.
1//////////////////////////////////////////////////////////////
2///
3/// \file network.h
4/// This file Defines everything related to networking
5///
6/// //////////////////////////////////////////////////////////
7#ifndef NETWORK_H
8#define NETWORK_H
9
10
11#include <stdlib.h>
12#include <stdio.h>
13#include <stdint.h>
14#include <strings.h>
15#include <arpa/inet.h>
16
17#include <SNF/SNF.h>
18#include <SNF/clt.h>
19#include <SNF/thpool.h>
20#include <SNF/vars.h>
21
22
23/// @brief the main Socket that accepts new incoming connections
24/// @warning Do not modify it's contents unless you know what you're doing.
25extern int SNF_SERVER_SOCKET;
26/// @brief Structure that saves the Server's sockaddr_in
27/// @warning Do not modify it's contents unless you know what you're doing.
28extern struct sockaddr_in SNF_SERVER_ADDR;
29/// @brief Structure that saves the Client's sockaddr_in
30/// @warning Do not modify it's contents unless you know what you're doing.
31extern struct sockaddr_in SNF_CLIENT_ADDR;
32/// @brief Used for accept's length argument.
33/// @warning Do not modify it's contents unless you know what you're doing.
34extern socklen_t SNF_CLIENT_LEN;
35
36/// @brief Macro that defines the Total data tranferred so far
37/// @warning Innacurate for now
38#define SNF_Total_Data (SNF_Total_Data_Rcv + SNF_Total_Data_Snt)
39/// @brief Saves the Total data received so far
40/// @warning Innacurate for now
41extern _Atomic uint64_t SNF_Total_Data_Rcv;
42/// @brief Saves the Total data sent so far
43/// @warning Innacurate for now
44extern _Atomic uint64_t SNF_Total_Data_Snt;
45
46/// @brief Character that sceparates each argument (To be Removed)
47#define UNIT_SCEPARATOR "\x1F"
48
49/// @brief Initializes the Network Framwork
50extern void snf_network_init();
51/// @brief See snf_thpool_join
52extern void snf_network_join();
53
54/// @brief Sends a Buffer to Client's socket's file descriptor
55/// @param Client Pointer to the Client's SNF_CLT instance
56/// @param Buffer Buffer to send
57/// @param _Size Size of the Buffer (See Note )
58/// @return The following possible results:
59/// * **-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.
60/// * **int** The amount of data sent.
61/// @note The <strong>_Size</strong> parameter could react differently depeding on it's value
62/// * If <strong>_Size</strong> < 0 then it will assume the **Buffer** is a string and send 4 bytes indicating the size (See \ref snf_uint32_to_bytes on how those 4 bytes are written ) and then send the buffer.
63/// * else it will send the **Buffer** and the length will be <strong>_Size</strong>
64extern int snf_snd(SNF_CLT *Client, const char *Buffer, int _Size);
65
66/// @brief Receives a Buffer from Client's socket's file descriptor
67/// @param Client Pointer to the Client's SNF_CLT instance
68/// @param Buffer Received Buffer
69/// @param _Size Expected Size
70/// @param _Flags Flags that will be passed to recv()
71/// @return The following possible results:
72/// * **-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.
73/// * **int** The amount of data sent.
74/// @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**.
75/// \note There is are re-definitions of snf_recv_ and are:
76/// * snf_rcv()
77/// * snf_rcv_PEEK()
78extern int snf_rcv_(SNF_CLT *Client, void *Buffer, int _Size, int _Flags);
79///@brief Same as \ref snf_rcv_ how ever <strong>_Flags</strong> will be 0
80#define snf_rcv(Client, Buffer, _Size) snf_rcv_(Client, Buffer, _Size, 0)
81///@brief Same as \ref snf_rcv_ how ever <strong>_Flags</strong> will be MSG_PEEK
82#define snf_rcv_PEEK(Client, Buffer, _Size) snf_rcv_(Client, Buffer, _Size, MSG_PEEK)
83
84#endif
Main Header FileThis File Calls for all the header files exisitng in this library,...
This file Defines everything related to handling Clients.
_Atomic uint64_t SNF_Total_Data_Snt
Saves the Total data sent so far.
struct sockaddr_in SNF_CLIENT_ADDR
Structure that saves the Client's sockaddr_in.
struct sockaddr_in SNF_SERVER_ADDR
Structure that saves the Server's sockaddr_in.
int snf_snd(SNF_CLT *Client, const char *Buffer, int _Size)
Sends a Buffer to Client's socket's file descriptor.
_Atomic uint64_t SNF_Total_Data_Rcv
Saves the Total data received so far.
socklen_t SNF_CLIENT_LEN
Used for accept's length argument.
int SNF_SERVER_SOCKET
the main Socket that accepts new incoming connections
int snf_rcv_(SNF_CLT *Client, void *Buffer, int _Size, int _Flags)
Receives a Buffer from Client's socket's file descriptor.
void snf_network_init()
Initializes the Network Framwork.
void snf_network_join()
See snf_thpool_join.
The structure for each saved client.
Definition clt.h:24
this file Defines everything related to ThreadPool
this file Defines everything related to Globaly accessed variable