recreate y_socket_t repo
This commit is contained in:
@@ -1,24 +0,0 @@
|
||||
#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 */
|
||||
@@ -1,8 +0,0 @@
|
||||
#ifndef __Y_QUEUE_T_H__
|
||||
#define __Y_QUEUE_T_H__
|
||||
|
||||
#include "y_socket/y_threads.h"
|
||||
|
||||
|
||||
|
||||
#endif /*__Y_QUEUE_T_H__*/
|
||||
@@ -1,29 +0,0 @@
|
||||
#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 */
|
||||
@@ -1,42 +0,0 @@
|
||||
#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 */
|
||||
@@ -1,18 +0,0 @@
|
||||
#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__*/
|
||||
@@ -1 +0,0 @@
|
||||
#include "y_socket/y_client.h"
|
||||
@@ -1 +0,0 @@
|
||||
#include "y_socket/y_queue.h"
|
||||
@@ -1,2 +0,0 @@
|
||||
#include "y_socket/y_server.h"
|
||||
|
||||
@@ -1,3 +0,0 @@
|
||||
#include "y_socket/y_threads.h"
|
||||
|
||||
|
||||
@@ -1,69 +0,0 @@
|
||||
|
||||
|
||||
|
||||
|
||||
NAME_TEST=is_good
|
||||
CC=gcc
|
||||
ROOT_DIR=$(PWD)
|
||||
YTESTDIR=$(PWD)/../../ytest_t
|
||||
|
||||
SOCDIR=$(PWD)/..
|
||||
INCLUDE_DIR=$(PWD)/../include
|
||||
CFLAGS=-I$(INCLUDE_DIR) #"-D DEBUG=1"
|
||||
LDFLAGS=-L$(YTESTDIR) -lytest -lOpenCL
|
||||
|
||||
#SRC_DIR=$(ROOT_DIR)/src
|
||||
#SRC=$(wildcard */*/*.c)
|
||||
SRC=$(wildcard **/**/*.c)
|
||||
#HEADS=$(OBJS:.o=.h)
|
||||
TEST_DIR=$(PWD)
|
||||
|
||||
EXECSRC=$(NAME_TEST).c
|
||||
#EXECSRC=openF.c
|
||||
|
||||
EXEC=launch_$(NAME_TEST)_m
|
||||
|
||||
SOCRC=$(SOCDIR)/src/y_socket/y_socket.c
|
||||
SOCSRC=$(wildcard ../src/*/*.c)
|
||||
SOCSRC_O=$(SOCSRC:.c=.o)
|
||||
|
||||
|
||||
|
||||
|
||||
TOPTARGETS := all clean
|
||||
|
||||
DEPS=$(YTESTDIR) $(SOCDIR)
|
||||
|
||||
OBJ=$(SOCSRC_O)
|
||||
|
||||
LIB_YTEST=$(YTESTDIR)/libytest.so
|
||||
|
||||
|
||||
$(TOPTARGETS): $(DEPS)
|
||||
|
||||
$(DEPS):
|
||||
$(MAKE) -C $@ $(MAKECMDGOALS)
|
||||
|
||||
|
||||
#PERMSRC_O=$(PERMSRC:.c=.o)
|
||||
#SETTSRC_O=$(PWD)/../src/set_theoric_t/set_theoric_t.o
|
||||
#SETTSRC_O=$(SETTSRC:.c=.o)
|
||||
#TOOLSRC=$(TOOLDIR)/src/tools_t/tools_t.c
|
||||
#TOOLSRC_O=$(TOOLSRC:.c=.o)
|
||||
|
||||
|
||||
all: $(EXEC) $(LIB_YTEST)
|
||||
|
||||
$(EXEC): $(EXECSRC) $(OBJ)
|
||||
$(CC) -o $@ $^ $(CFLAGS) $(LDFLAGS)
|
||||
|
||||
.PHONY: clean mrproper
|
||||
|
||||
clean:
|
||||
rm -f $(OBJ)
|
||||
|
||||
mrproper: clean
|
||||
rm -f $(EXEC)
|
||||
|
||||
run: $(EXEC)
|
||||
$(EXEC) -h
|
||||
@@ -1,35 +0,0 @@
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <stdbool.h>
|
||||
|
||||
// for sleep !
|
||||
#ifdef __linux__
|
||||
#include <unistd.h>
|
||||
#elif _WIN32
|
||||
#include <windows.h>
|
||||
#endif
|
||||
|
||||
#include "ftest/ftest.h"
|
||||
#include "ftest/ftest_array.h"
|
||||
#include "fmock/fmock.h"
|
||||
|
||||
|
||||
//#include "permutation_t/permutation_t.h"
|
||||
#include "y_socket/y_socket.h"
|
||||
|
||||
#define VALGRIND_ 1
|
||||
|
||||
TEST(first){
|
||||
|
||||
LOG("hey%s\n"," you");
|
||||
|
||||
}
|
||||
|
||||
|
||||
int main(int argc, char **argv){
|
||||
|
||||
|
||||
run_all_tests_args(argc, argv);
|
||||
|
||||
return 0;
|
||||
}
|
||||
@@ -1,42 +1,58 @@
|
||||
# lib: -lysocket
|
||||
PROJECT_LIB=libysocket.so
|
||||
CC=gcc
|
||||
INCLUDE_DIRS=$(PWD)
|
||||
INCLUDE_DIRS=$(PWD)/include
|
||||
SOCDIR=$(PWD)
|
||||
#$(wildcard $(PWD)/**/include)
|
||||
|
||||
YLISTDIR=$(PWD)/../list_t
|
||||
|
||||
INCLUDE=-I$(PWD)/include
|
||||
INCLUDE=-I$(INCLUDE_DIRS) -I$(YLISTDIR)/src
|
||||
CFLAGS=-g -lpthread -Wall -Werror -fpic $(INCLUDE) #"-D DEBUG=1"
|
||||
#LDFLAGS=
|
||||
|
||||
TOPTARGETS := all clean #update_headers
|
||||
|
||||
#SRC=$(wildcard y*/src/**/**/*.c)
|
||||
SRC=$(wildcard src/*/*.c)
|
||||
OBJ=$(SRC:.c=.o)
|
||||
YSOCKSRC=$(PWD)/src/y_socket_t/y_socket_t.c
|
||||
YSOCKSRC_O=$(YSOCKSRC:.c=.o)
|
||||
|
||||
#SUBDIRS :=$(wildcard y*) $(TOOLDIR) $(BARPDIR)
|
||||
YNODESRC=$(PWD)/src/y_socket_t/y_node_t.c
|
||||
YNODESRC_O=$(YNODESRC:.c=.o)
|
||||
|
||||
#export
|
||||
YLISTSRC=$(YLISTDIR)/src/list_t/list_t.c
|
||||
YLISTSRC_O=$(YLISTSRC:.c=.o)
|
||||
|
||||
|
||||
#$(TOPTARGETS): $(SUBDIRS)
|
||||
|
||||
TOPTARGETS := all clean
|
||||
|
||||
DEPS=$(YLISTDIR)
|
||||
|
||||
OBJ=$(YSOCKSRC_O) $(YNODESRC_O) $(YLISTSRC_O)
|
||||
|
||||
$(TOPTARGETS): $(DEPS)
|
||||
|
||||
|
||||
all: $(PROJECT_LIB)
|
||||
|
||||
#update_headers
|
||||
|
||||
|
||||
|
||||
$(PROJECT_LIB): $(OBJ)
|
||||
echo $(OBJ)
|
||||
echo "objects:" $(OBJ)
|
||||
#$(CC) -shared -o $@ $^ $(INCLUDE) $(LDFLAGS)
|
||||
#$(CC) -shared -o $@ $^ $(LDFLAGS)
|
||||
$(CC) -shared -o $@ $^ $(CFLAGS)
|
||||
|
||||
|
||||
$(SUBDIRS):
|
||||
$(MAKE) -C $@ $(MAKECMDGOALS)
|
||||
$(YSOCKSRC_O): $(YSOCKSRC) $(YNODESRC_O)
|
||||
$(CC) -o $@ -c $< $(CFLAGS)
|
||||
|
||||
$(YNODESRC_O): $(YNODESRC) $(YSOCKSRC_O) $(YLISTSRC_O)
|
||||
$(CC) -o $@ -c $< $(CFLAGS)
|
||||
|
||||
|
||||
$(DEPS):
|
||||
$(MAKE) -C $@ $(MAKECMDGOALS)
|
||||
|
||||
|
||||
# .PHONY: $(TOPTARGETS) $(SUBDIRS)
|
||||
@@ -50,7 +66,7 @@ mrproper: clean
|
||||
rm -f $(PROJECT_LIB)
|
||||
|
||||
install:
|
||||
cp libytest.so /usr/lib/
|
||||
cp libysocket.so /usr/lib/
|
||||
@if [ -d /usr/local/include ] ; then\
|
||||
echo "copy include to /usr/local/include/" ;\
|
||||
cp -r include/* /usr/local/include/;\
|
||||
@@ -60,13 +76,13 @@ install:
|
||||
fi
|
||||
|
||||
uninstall:
|
||||
rm /usr/lib/libytest.so
|
||||
rm /usr/lib/libysocket.so
|
||||
@if [ -d /usr/local/include ] ; then\
|
||||
echo "remove from /usr/local/include/" ;\
|
||||
rm -r /usr/local/include/y_socket ;\
|
||||
rm -r /usr/local/include/y_socket_t ;\
|
||||
else\
|
||||
echo "remove from /usr/include/" ;\
|
||||
rm -r /usr/include/y_socket ;\
|
||||
rm -r /usr/include/y_socket_t ;\
|
||||
fi
|
||||
|
||||
|
||||
@@ -0,0 +1,29 @@
|
||||
#ifndef __Y_NODE_T_H__C
|
||||
#define __Y_NODE_T_H__C
|
||||
|
||||
#include <netinet/in.h>
|
||||
|
||||
//#include "y_socket_t/y_socket_t.h"
|
||||
#include "list_t/list_t.h"
|
||||
|
||||
|
||||
typedef struct y_node_t{
|
||||
//char *id;
|
||||
struct sockaddr_storage addr;
|
||||
socklen_t addr_len;
|
||||
} y_NODE_T;
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
GENERATE_LIST_ALL(y_NODE_T)
|
||||
|
||||
void init_len_y_NODE_T(y_NODE_T *node);
|
||||
void init_len_list_y_NODE_T(struct main_list_y_NODE_T *listNodes);
|
||||
|
||||
int y_NODE_T_cmp(y_NODE_T nodeA, y_NODE_T nodeB);
|
||||
|
||||
struct list_y_NODE_T * search_node_in_list_y_NODE_T(struct main_list_y_NODE_T *listNodes, y_NODE_T node);
|
||||
|
||||
#endif /* __Y_NODE_T_H__C */
|
||||
@@ -0,0 +1,52 @@
|
||||
#ifndef Y_SOCKET_T_H__C
|
||||
#define Y_SOCKET_T_H__C
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <unistd.h>
|
||||
#include <string.h>
|
||||
|
||||
//#include <sys/socket.h>
|
||||
#include <netinet/in.h>
|
||||
#include <netdb.h>
|
||||
#include <arpa/inet.h>
|
||||
|
||||
//#include <fcntl.h>
|
||||
|
||||
#include <pthread.h>
|
||||
#include <poll.h>
|
||||
#include <errno.h>
|
||||
#include <signal.h>
|
||||
|
||||
|
||||
#include "y_socket_t/y_node_t.h"
|
||||
|
||||
#define BUF_SIZE 500
|
||||
|
||||
#define type4
|
||||
#define type6 6
|
||||
|
||||
enum ipVersions{
|
||||
v4,v6,nbIpVersion
|
||||
};
|
||||
|
||||
extern const int af_array[nbIpVersion];//={AF_INET, AF_INET6};
|
||||
|
||||
struct y_socket_t{
|
||||
struct pollfd fds[nbIpVersion];
|
||||
char * port;
|
||||
struct main_list_y_NODE_T nodes;
|
||||
|
||||
};
|
||||
|
||||
struct y_socket_t * y_socket_create(char * port);
|
||||
|
||||
void y_socket_free(struct y_socket_t *socket);
|
||||
|
||||
// type = nothing if v4, 6 if v6
|
||||
#define GET_IN_type_ADDR(PointerSockAddr,type) \
|
||||
((struct sockaddr_in##type *)(PointerSockAddr))->sin##type##_addr.s##type##_addr
|
||||
|
||||
|
||||
|
||||
#endif /* Y_SOCKET_T_H__C */
|
||||
@@ -0,0 +1,45 @@
|
||||
#include "y_socket_t/y_node_t.h"
|
||||
#include "y_socket_t/y_socket_t.h"
|
||||
|
||||
// type=nothing if v4, type=6 if v6
|
||||
#define GET_type_IN_ADDR(PointerSockAddr,type) \
|
||||
((struct sockaddr_in##type *)(PointerSockAddr))->sin##type##_addr.s##type##_addr
|
||||
|
||||
GEN_LIST_ALL(y_NODE_T)
|
||||
|
||||
|
||||
void init_len_y_NODE_T(y_NODE_T *node){
|
||||
node->addr_len=sizeof(struct sockaddr_storage);
|
||||
}
|
||||
void init_len_list_y_NODE_T(struct main_list_y_NODE_T *listNodes){
|
||||
FOR_LIST_FORM_BEGIN(y_NODE_T, listNodes){
|
||||
init_len_y_NODE_T(&(listNodes->current_list->value));
|
||||
}
|
||||
}
|
||||
|
||||
int y_NODE_T_cmp(y_NODE_T nodeA, y_NODE_T nodeB){
|
||||
int ret = nodeA.addr_len - nodeB.addr_len;
|
||||
if(ret == 0){
|
||||
ret = nodeA.addr.ss_family - nodeB.addr.ss_family;
|
||||
if(ret == 0){
|
||||
if(nodeA.addr.ss_family == AF_INET){
|
||||
//ret = ((struct sockaddr_in*)&(nodeA.addr))->sin_addr.s_addr - ((struct sockaddr_in*)&(nodeB.addr))->sin_addr.s_addr;
|
||||
ret = GET_IN_type_ADDR(&(nodeA.addr),) - GET_IN_type_ADDR(&(nodeB.addr),);
|
||||
}else
|
||||
if(nodeA.addr.ss_family == AF_INET6){
|
||||
ret = memcmp(GET_IN_type_ADDR(&(nodeA.addr),6), GET_IN_type_ADDR(&(nodeB.addr),6), 8);
|
||||
//ret = memcmp(((struct sockaddr_in6*)&(nodeA.addr))->sin6_addr.s6_addr , ((struct sockaddr_in6*)&(nodeB.addr))->sin6_addr.s6_addr, 8);
|
||||
}
|
||||
}
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
struct list_y_NODE_T * search_node_in_list_y_NODE_T(struct main_list_y_NODE_T *listNodes, y_NODE_T node){
|
||||
FOR_LIST_FORM_BEGIN(y_NODE_T, listNodes){
|
||||
if(y_NODE_T_cmp(node, listNodes->current_list->value) == 0){
|
||||
return listNodes->current_list;
|
||||
}
|
||||
}
|
||||
return NULL;
|
||||
|
||||
}
|
||||
@@ -1,4 +1,19 @@
|
||||
#include "y_socket/y_socket.h"
|
||||
#include "y_socket_t/y_socket_t.h"
|
||||
|
||||
const int af_array[nbIpVersion]={AF_INET, AF_INET6};
|
||||
|
||||
struct y_socket_t * y_socket_create(char *port){
|
||||
struct y_socket_t *sock_temp=malloc(sizeof(struct y_socket_t));
|
||||
sock_temp->port=port;
|
||||
return sock_temp;
|
||||
}
|
||||
|
||||
void y_socket_free(struct y_socket_t *socket){
|
||||
|
||||
|
||||
free(socket);
|
||||
}
|
||||
|
||||
|
||||
#if 0
|
||||
struct y_server_t server;
|
||||
@@ -0,0 +1,68 @@
|
||||
|
||||
|
||||
|
||||
|
||||
NAME_TEST=is_good
|
||||
CC=gcc
|
||||
YTESTDIR=$(PWD)/../../ytest_t
|
||||
YLISTDIR=$(PWD)/../../list_t
|
||||
|
||||
ROOT_DIR=$(PWD)/..
|
||||
INCLUDE_DIR=$(ROOT_DIR)/include
|
||||
CFLAGS=-I$(INCLUDE_DIR) -I$(YTESTDIR)/include_ytest/include -I$(YLISTDIR)/src
|
||||
LDFLAGS=-L$(YTESTDIR) -lytest -lpthread -lm -lOpenCL
|
||||
|
||||
#SRC_DIR=$(ROOT_DIR)/src
|
||||
#SRC=$(wildcard */*/*.c)
|
||||
#SRC=$(wildcard **/**/*.c)
|
||||
|
||||
#OBJ=$(SRC:.c=.o)
|
||||
|
||||
#HEADS=$(OBJS:.o=.h)
|
||||
#TEST_DIR=$(PWD)
|
||||
|
||||
EXECSRC=$(NAME_TEST).c
|
||||
EXEC=launch_$(NAME_TEST)_m
|
||||
|
||||
YSOCKSRC=$(ROOT_DIR)/src/y_socket_t/y_socket_t.c
|
||||
YSOCKSRC_O=$(YSOCKSRC:.c=.o)
|
||||
|
||||
YNODESRC=$(ROOT_DIR)/src/y_socket_t/y_node_t.c
|
||||
YNODESRC_O=$(YNODESRC:.c=.o)
|
||||
|
||||
YLISTSRC=$(YLISTDIR)/src/list_t/list_t.c
|
||||
YLISTSRC_O=$(YLISTSRC:.c=.o)
|
||||
|
||||
TOPTARGETS := all clean
|
||||
|
||||
DEPS=$(YTESTDIR) $(YLISTDIR) $(ROOT_DIR)
|
||||
|
||||
OBJ=$(YSOCKSRC_O) $(YNODESRC_O) $(YLISTSRC_O)
|
||||
|
||||
|
||||
LIB_YTEST=$(YTESTDIR)/libytest.so
|
||||
|
||||
LIB_YSOCK=$(PWD)/../libysocket.so
|
||||
|
||||
$(TOPTARGETS): $(DEPS)
|
||||
|
||||
$(DEPS):
|
||||
$(MAKE) -C $@ $(MAKECMDGOALS)
|
||||
|
||||
|
||||
|
||||
all: $(EXEC) $(LIB_YSOCK) $(LIB_YTEST)
|
||||
|
||||
$(EXEC): $(EXECSRC) $(OBJ)
|
||||
$(CC) -o $@ $^ $(CFLAGS) $(LDFLAGS)
|
||||
|
||||
.PHONY: clean mrproper
|
||||
|
||||
clean:
|
||||
rm -f $(OBJ)
|
||||
|
||||
mrproper: clean
|
||||
rm -f $(EXEC)
|
||||
|
||||
run: $(EXEC)
|
||||
$(EXEC) -h
|
||||
@@ -0,0 +1,122 @@
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <stdbool.h>
|
||||
|
||||
// for sleep !
|
||||
#ifdef __linux__
|
||||
#include <unistd.h>
|
||||
#elif _WIN32
|
||||
#include <windows.h>
|
||||
#endif
|
||||
|
||||
#include "ftest/ftest.h"
|
||||
#include "ftest/ftest_array.h"
|
||||
#include "fmock/fmock.h"
|
||||
|
||||
//#include "permutation_t/permutation_t.h"
|
||||
#include "y_socket_t/y_socket_t.h"
|
||||
#include "y_socket_t/y_node_t.h"
|
||||
|
||||
//#include <netinet/in.h>
|
||||
//#include <sys/socket.h>
|
||||
//#include <arpa/inet.h>
|
||||
|
||||
#define VALGRIND_ 1
|
||||
|
||||
TEST(first){
|
||||
|
||||
struct y_socket_t *firstSock = y_socket_create("1600");
|
||||
LOG("create y_socket_t in port |%s|\n",firstSock->port);
|
||||
|
||||
y_socket_free(firstSock);
|
||||
|
||||
for(int af=v4; af<=v6;++af)
|
||||
LOG("af_array[%d]=%d\n",af,af_array[af]);
|
||||
|
||||
|
||||
}
|
||||
|
||||
TEST(list_nodes){
|
||||
struct main_list_y_NODE_T * listNodes = create_var_list_y_NODE_T();
|
||||
|
||||
LOG("main_list_y_NODE_T created\n");
|
||||
|
||||
y_NODE_T firstNode;
|
||||
|
||||
push_back_list_y_NODE_T(listNodes, firstNode);
|
||||
|
||||
|
||||
free_all_var_list_y_NODE_T(listNodes);
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
TEST(equalNode){
|
||||
y_NODE_T nA, nB;
|
||||
init_len_y_NODE_T(&nA);
|
||||
init_len_y_NODE_T(&nB);
|
||||
|
||||
nA.addr.ss_family=AF_INET;
|
||||
nB.addr.ss_family=AF_INET;
|
||||
|
||||
//((struct sockaddr_in*)&(nA.addr))->sin_addr.s_addr = inet_addr("192.168.1.2");
|
||||
//((struct sockaddr_in*)&(nB.addr))->sin_addr.s_addr = inet_addr("192.168.1.2");
|
||||
|
||||
GET_IN_type_ADDR(&(nA.addr),) = inet_addr("1.1.1.1");
|
||||
GET_IN_type_ADDR(&(nB.addr),) = inet_addr("1.1.1.1");
|
||||
|
||||
LOG("nA = %d\n",GET_IN_type_ADDR(&(nA.addr),));
|
||||
LOG("nB = %d\n",GET_IN_type_ADDR(&(nB.addr),));
|
||||
|
||||
EXPECT_EQ(0, y_NODE_T_cmp(nA,nB));
|
||||
GET_IN_type_ADDR(&(nB.addr),) = inet_addr("0.1.1.1");
|
||||
LOG("diff = %d\n", y_NODE_T_cmp(nA,nB));
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
TEST(searchNode){
|
||||
y_NODE_T nA, nB;
|
||||
init_len_y_NODE_T(&nA);
|
||||
init_len_y_NODE_T(&nB);
|
||||
|
||||
nA.addr.ss_family=AF_INET;
|
||||
nB.addr.ss_family=AF_INET;
|
||||
|
||||
//((struct sockaddr_in*)&(nA.addr))->sin_addr.s_addr = inet_addr("192.168.1.2");
|
||||
//((struct sockaddr_in*)&(nB.addr))->sin_addr.s_addr = inet_addr("192.168.1.2");
|
||||
|
||||
GET_IN_type_ADDR(&(nA.addr),) = inet_addr("1.1.1.1");
|
||||
GET_IN_type_ADDR(&(nB.addr),) = inet_addr("1.1.1.2");
|
||||
|
||||
LOG("nA = %d\n",GET_IN_type_ADDR(&(nA.addr),));
|
||||
LOG("nB = %d\n",GET_IN_type_ADDR(&(nB.addr),));
|
||||
|
||||
struct main_list_y_NODE_T *listNodes = create_var_list_y_NODE_T();
|
||||
push_back_list_y_NODE_T(listNodes, nA);
|
||||
push_back_list_y_NODE_T(listNodes, nB);
|
||||
GET_IN_type_ADDR(&(nA.addr),) = inet_addr("1.1.1.3");
|
||||
push_back_list_y_NODE_T(listNodes, nA);
|
||||
|
||||
GET_IN_type_ADDR(&(nB.addr),) = inet_addr("0.1.1.1");
|
||||
// push_back_list_y_NODE_T(listNodes, nB);
|
||||
|
||||
EXPECT_TRUE(NULL == search_node_in_list_y_NODE_T(listNodes, nB));
|
||||
GET_IN_type_ADDR(&(nA.addr),) = inet_addr("1.1.1.3");
|
||||
EXPECT_FALSE(NULL == search_node_in_list_y_NODE_T(listNodes, nA));
|
||||
|
||||
free_all_var_list_y_NODE_T(listNodes);
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
int main(int argc, char **argv){
|
||||
|
||||
|
||||
run_all_tests_args(argc, argv);
|
||||
|
||||
return 0;
|
||||
}
|
||||
Reference in New Issue
Block a user