To design a good project must have a sound source framework
A body structure with a function pointer and the data fields of data processing, to realize the function of increasing the empty list management list traversal node delete nodes operate on each node
Sign the agreement and then implement the socket to add objects to manage the list
Use the list to achieve operational management agreement to create a linked list (LinkListInit) objects,
Add a registered protocol (tail add a list node (RegisterProtocol)),
Delete protocol (head Delete (DeleteProtocol)),
Traversing the list of nodes and functions to match the operation (TraverseList) each node,
Agreement to delete the specified ID (remove the specified node (DeleteNode)),
Empty list (to delete the node (ClearProtocol)), destruction protocol object (the list object blank (DestoryProtocolStack)), returns the list length (length of the parent list object (GetCurrentSize)).
Sign up HTTP protocol (InitHttp):. 1 new (target) node (malloc)
2. Object Set (T_DATA where id = HTTP; flag = inuse; init = additional write function (InitHttpNode) connection or listening; SendFunction = realize sending further function (HttpSendFunction))
(InitHttpNode: Set ip address or listening port connecting with ... HttpSendFunction: transmitting send_buffer used ....
3. Add the create and set a good target to (RegisterProtocol) to the object in the list
Registration HTTPS TCP source framework agreement with HTTP
1 #include <stdio.h> 2 #include <stdlib.h> 3 4 #define BUFFER_SIZE 0x1000 5 6 #define HTTP 0x1 7 #define HTTPS 0x2 8 #define TCP 0x3 9 10 #define INUSE 0x1 11 #define UNUSE 0x2 12 13 #define EMPTY 0x2 14 #define NOEMPTY 0x3 15 16 #define false 0 17 #define ture 1 18 19 /* Application parameters */ 20 #define DEBUG (1) 21 /* Debug prints */ 22 #if DEBUG 23 #define DBG_PRINT(fmt, args...) do{printf("[*]Listlink: <%s>: " fmt "\n" \ 24 ,__func__, ##args); } while (false) 25 #else 26 #define DBG_PRINT(...) do {} while (false) 27 #endif 28 29 30 typedef unsigned char u8; 31 typedef unsigned short u16; 32 typedef unsigned int u32; 33 34 typedef struct _T_NodeStruct{ 35 u8 id; 36 u8 flag; 37 u8 send_buffer[BUFFER_SIZE]; 38 u32 (* Init)(void); 39 u32 (* SendFunction)(int fd,u8 *send_buffer,u32 length); 40 }T_NodeStruct; 41 typedef T_NodeStruct * Pt_NodeStruct; 42 43 44 typedef struct _T_ListLinkNode{ 45 T_NodeStruct t_data; 46 struct_T_ListLinkNode * pt_next; 47 } T_ListLinkNode; 48 typedef T_ListLinkNode * Pt_ListLinkNode; 49 50 typedef struct _T_list { 51 is Pt_ListLinkNode Pfront; 52 is Pt_ListLinkNode prear; 53 is U32 length; 54 is } T_list; 55 typedef T_list * pt_list; 56 is 57 is 58 void ClearProtocal (pt_list ptlist ); // Clear protocols utilize DeleteProtocol Register call to delete a node in the list of all 59 void DeleteNode (pt_list ptlist, id U8); // delete the selected node id 60 voidDeleteProtocal (Pt_list ptlist, Pt_ListLinkNode ptlistnode) ; // remove header node and the backup data to be deleted, the second parameter may be NULL to not save 61 is void DestoryProtocalStack (pt_list ptlist); // set all the empty list node 62 is U32 GetCurrentSize (pt_list ptlist); // get the current list of length 63 U8 IsEmpty (pt_list ptlist); // empty sentenced 64- pt_list ListLinkInit ( void ); // create the list object 65 void RegisterProtocal (pt_list ptlist, Pt_ListLinkNode ptlistnode); // Register agreement, to add a node to the list of objects created, managed 66 void TraverseList (pt_list ptlist, void (* Traverse) (Pt_ListLinkNode ptlistlinknode, U8 *));
// matching function, the function passed in each of the linked list nodes operate