2016-09-16 00:09:04 +02:00
|
|
|
#ifndef __TCPDSERVER_H__
|
|
|
|
#define __TCPDSERVER_H__
|
|
|
|
|
2016-09-16 15:22:14 +02:00
|
|
|
#include <sys/types.h>
|
|
|
|
#include <sys/socket.h>
|
|
|
|
#include <netinet/in.h>
|
|
|
|
#include <arpa/inet.h>
|
2016-09-16 00:09:04 +02:00
|
|
|
|
2016-12-14 22:56:13 +01:00
|
|
|
#include "../../lib/communication.h"
|
2016-09-29 19:02:05 +02:00
|
|
|
|
2016-09-16 21:41:23 +02:00
|
|
|
typedef struct {
|
2016-09-23 20:27:26 +02:00
|
|
|
struct sockaddr_in c_addr;
|
2016-09-16 21:41:23 +02:00
|
|
|
int sfd;
|
2016-09-21 20:38:04 +02:00
|
|
|
int index;
|
2016-09-23 20:27:26 +02:00
|
|
|
} client_data;
|
2016-09-16 21:41:23 +02:00
|
|
|
|
2016-09-29 19:02:05 +02:00
|
|
|
//informations for server to listen at a address
|
|
|
|
typedef struct {
|
|
|
|
struct sockaddr_in addr;
|
|
|
|
char * request;
|
2018-10-04 00:30:47 +02:00
|
|
|
struct ipc_client *p;
|
2016-09-29 19:02:05 +02:00
|
|
|
} info_request;
|
|
|
|
|
|
|
|
int initConnection (const info_request *req);
|
2016-09-22 18:38:24 +02:00
|
|
|
void endConnection (int sock);
|
2016-09-18 01:03:37 +02:00
|
|
|
|
2016-10-02 14:33:58 +02:00
|
|
|
void printAddr (struct sockaddr_in *csin);
|
2016-09-18 01:03:37 +02:00
|
|
|
|
2016-10-14 17:47:08 +02:00
|
|
|
void write_message(int sock, const char *buffer, size_t size);
|
2016-09-16 15:22:14 +02:00
|
|
|
int read_message(int sock, char *buffer);
|
2016-09-18 01:03:37 +02:00
|
|
|
|
|
|
|
//2 threads for listen and send data
|
2016-09-21 20:38:04 +02:00
|
|
|
void * service_thread(void * pdata);
|
2016-09-18 01:03:37 +02:00
|
|
|
|
|
|
|
//parse the first message from client in service and version
|
2016-09-18 00:17:47 +02:00
|
|
|
void parseServiceVersion(char * buf, char ** service, int *version);
|
2016-09-18 01:03:37 +02:00
|
|
|
|
|
|
|
//create 2 pathnames such as : pid-index-version-in/out
|
2016-09-21 20:38:04 +02:00
|
|
|
void inOutPathCreate(char ** pathname, int index, int version);
|
2016-09-18 01:03:37 +02:00
|
|
|
|
|
|
|
//create a fifo file
|
2016-09-16 21:41:23 +02:00
|
|
|
int fifo_create (char * path);
|
2016-09-16 00:09:04 +02:00
|
|
|
|
2016-09-21 20:38:04 +02:00
|
|
|
//create first message for a service : pid index version
|
|
|
|
void makePivMessage(char ** piv, int pid, int index, int version);
|
|
|
|
|
2018-10-03 21:52:11 +02:00
|
|
|
void * ipc_server_thread(void *reqq);
|
2016-09-29 19:02:05 +02:00
|
|
|
|
2016-10-02 14:33:58 +02:00
|
|
|
void * client_thread(void *reqq);
|
|
|
|
|
2018-10-03 21:52:11 +02:00
|
|
|
int ipc_server_get_new_request(char *buf, info_request *req);
|
2016-09-29 19:02:05 +02:00
|
|
|
|
|
|
|
void request_print (const info_request *req);
|
|
|
|
|
2018-10-04 00:30:47 +02:00
|
|
|
void main_loop(struct ipc_service *srv);
|
2016-09-29 19:02:05 +02:00
|
|
|
|
2016-09-16 00:09:04 +02:00
|
|
|
|
2016-12-14 22:56:13 +01:00
|
|
|
#endif
|