Obsolete
/
libipc-old
Archived
3
0
Fork 0

some advancement for the server

more_to_read
lapupe 2016-09-18 00:17:47 +02:00
parent 0498b2b134
commit a1612c5ca9
3 changed files with 44 additions and 7 deletions

View File

@ -58,6 +58,8 @@ int main(int argc, char ** argv) {
} }
write_message(sock, "pongd 5"); write_message(sock, "pongd 5");
sleep(1);
write_message(sock, "is it working ???");
close(sock); close(sock);

View File

@ -1,4 +1,6 @@
#include "tcpdserver.h" #include "tcpdserver.h"
#include "../lib.communication.h"
#include <sys/types.h> #include <sys/types.h>
#include <sys/socket.h> #include <sys/socket.h>
#include <netinet/in.h> #include <netinet/in.h>
@ -128,15 +130,13 @@ void * listen_thread(void * pdata) {
char *service; char *service;
int version; int version;
int n = read_message(pda->sfd, buffer); if (read_message(pda->sfd, buffer) == -1) {
if (n == -1) {
perror("read_message()"); perror("read_message()");
return NULL; return NULL;
}else { }else {
parseString(buffer, &service, &version); parseServiceVersion(buffer, &service, &version);
} }
// printf("%s\n", service);
// printf("%d\n", version);
/* TODO : service correspond au service que le client veut utiliser /* TODO : service correspond au service que le client veut utiliser
** il faut comparer service à un tableau qui contient les services ** il faut comparer service à un tableau qui contient les services
** disponibles ** disponibles
@ -162,10 +162,44 @@ void * listen_thread(void * pdata) {
return NULL; return NULL;
}*/ }*/
pthread_t senPid;
int ret = pthread_create( &sendPid, NULL, &send_thread, (void *) pda);
if (ret) {
perror("pthread_create()");
exit(errno);
} else {
printf("Creation of send thread \n");
}
while (1) {
int n = read_message(pda->sfd, buffer);
if (n > 0) {
printf("%s\n", buffer );
}
}
pthread_join(listenPid, NULL);
return NULL; return NULL;
} }
void parseString(char * buf, char ** service, int *version) { void * send_thread(void * pdata) {
p_data *pda = (p_data*) pdata;
int ret;
size_t msize = BUFSIZ;
char *buf = NULL;
while (1) {
ret = file_read(pda->fifoOut, &buf, &msize);
if (ret > 0) {
printf("%s\n",buf );
}
}
return NULL;
}
void parseServiceVersion(char * buf, char ** service, int *version) {
char *token = NULL, *saveptr = NULL; char *token = NULL, *saveptr = NULL;
char *str = NULL; char *str = NULL;
int i = 0; int i = 0;

View File

@ -9,6 +9,7 @@
typedef struct { typedef struct {
struct sockaddr_in c_sock; struct sockaddr_in c_sock;
int sfd; int sfd;
char * fifoOut;
} p_data; } p_data;
int initConnection (); int initConnection ();
@ -17,7 +18,7 @@ void printClientAddr (struct sockaddr_in *csin);
void write_message(int sock, const char *buffer); void write_message(int sock, const char *buffer);
int read_message(int sock, char *buffer); int read_message(int sock, char *buffer);
void * listen_thread(void * p_data); void * listen_thread(void * p_data);
void parseString(char * buf, char ** service, int *version); void parseServiceVersion(char * buf, char ** service, int *version);
void inOutPathCreate(char ** pathname, int version); void inOutPathCreate(char ** pathname, int version);
int fifo_create (char * path); int fifo_create (char * path);