add sockets
This commit is contained in:
@@ -0,0 +1,24 @@
|
||||
#ifndef Y_CLIENT_H__C
|
||||
#define Y_CLIENT_H__C
|
||||
|
||||
|
||||
#include <pthread.h>
|
||||
|
||||
#include "y_socket/y_socket.h"
|
||||
|
||||
|
||||
|
||||
struct y_client{
|
||||
size_t id;
|
||||
struct y_socket_t *socket;
|
||||
int nb_threads;
|
||||
pthread_t *thread_client;
|
||||
pthread_mutex_t *mut_client;
|
||||
|
||||
void *(*launch)(void*);
|
||||
|
||||
};
|
||||
|
||||
|
||||
|
||||
#endif /* Y_CLIENT_H__C */
|
||||
@@ -0,0 +1,8 @@
|
||||
#ifndef __Y_QUEUE_T_H__
|
||||
#define __Y_QUEUE_T_H__
|
||||
|
||||
#include "y_socket/y_threads.h"
|
||||
|
||||
|
||||
|
||||
#endif /*__Y_QUEUE_T_H__*/
|
||||
@@ -0,0 +1,29 @@
|
||||
#ifndef Y_SERVER_H__C
|
||||
#define Y_SERVER_H__C
|
||||
|
||||
#include <pthread.h>
|
||||
|
||||
#include "y_socket/y_socket.h"
|
||||
|
||||
|
||||
|
||||
struct y_server_t{
|
||||
struct y_socket_t *socket;
|
||||
// struct y_client_t *client;
|
||||
// int nb_clients;
|
||||
|
||||
|
||||
// int max_length_queue; //backlog;// max connexion
|
||||
|
||||
pthread_t *thread_server;
|
||||
pthread_mutex_t *mut_server;
|
||||
int nb_threads;
|
||||
|
||||
|
||||
void *(*launch)(void*);
|
||||
|
||||
};
|
||||
|
||||
|
||||
|
||||
#endif /* Y_SERVER_H__C */
|
||||
@@ -0,0 +1,42 @@
|
||||
#ifndef Y_SOCKET_H__C
|
||||
#define Y_SOCKET_H__C
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <unistd.h>
|
||||
#include <string.h>
|
||||
#include <arpa/inet.h>
|
||||
|
||||
#include <sys/ioctl.h>
|
||||
|
||||
#include <netinet/in.h>
|
||||
|
||||
#include <sys/socket.h>
|
||||
|
||||
#include <fcntl.h>
|
||||
|
||||
#include <pthread.h>
|
||||
|
||||
#include <signal.h>
|
||||
|
||||
struct y_socket_t{
|
||||
int fd; /* Socket descriptor, */
|
||||
int domain; /*AF_INET, AF_INET6 */
|
||||
int service; /*type: SOCK_STREAM: TCP, SOCK_DGRAM: UDP */
|
||||
int protocol; /* 0 */
|
||||
u_long interface;
|
||||
int port;
|
||||
int backlog;/*max_queue */
|
||||
|
||||
struct sockaddr_in *address; /* INADDR_ANY or */
|
||||
int address_len;
|
||||
};
|
||||
|
||||
struct y_socket_t * socket_create(int domain, int service, int protocol, u_long interface,
|
||||
int port, int backlog);
|
||||
|
||||
void socket_destroy(struct y_socket_t *socket);
|
||||
|
||||
|
||||
|
||||
|
||||
#endif /* Y_SOCKET_H__C */
|
||||
@@ -0,0 +1,18 @@
|
||||
#ifndef __Y_THREAD_H__
|
||||
#define __Y_THREAD_H__
|
||||
|
||||
|
||||
#include <pthread.h>
|
||||
|
||||
#include "y_socket/y_queue.h"
|
||||
|
||||
|
||||
struct y_threadpool{
|
||||
int nb_threads;
|
||||
pthread_cond_t cond_;
|
||||
pthread_mutex_t mut_;
|
||||
pthread_t *thread;
|
||||
void *(*launch)(void* arg);
|
||||
|
||||
};
|
||||
#endif /*__Y_THREAD_H__*/
|
||||
Reference in New Issue
Block a user