файлы туды-сюды (удалено лишнее в опчем)
This commit is contained in:
parent
1d845ec6a6
commit
27ccb8cd93
|
@ -0,0 +1,62 @@
|
|||
TARGET=$(shell basename `pwd`)
|
||||
SOURCES=$(wildcard *.c)
|
||||
OBJECTS=$(SOURCES:%.c=%.o)
|
||||
|
||||
#CFLAGS=-march=core2 -mtune=core2 -O2 -mfpmath=sse -msse4.1 -pipe
|
||||
#LDFLAGS=-Wl,-O1 -Wl,--as-needed
|
||||
|
||||
CFLAGS+=$(shell pkg-config --cflags liblist)
|
||||
LDFLAGS+=$(shell pkg-config --libs liblist) -lpthread
|
||||
|
||||
all: $(TARGET)
|
||||
|
||||
$(OBJECTS): $(SOURCES)
|
||||
|
||||
$(TARGET): $(OBJECTS)
|
||||
|
||||
echo-server: echo-server.o xerror.o
|
||||
|
||||
clean:
|
||||
$(RM) $(OBJECTS) $(TARGET)
|
||||
|
||||
.PHONY: all clean
|
||||
|
||||
# c++
|
||||
#TARGET=$(shell basename `pwd`)
|
||||
#SOURCES=$(wildcard *.cpp)
|
||||
#OBJECTS=$(SOURCES:%.cpp=%.o)
|
||||
#
|
||||
#all: $(TARGET)
|
||||
#
|
||||
#$(OBJECTS): $(SOURCES)
|
||||
#
|
||||
#$(TARGET): $(OBJECTS)
|
||||
# $(CXX) -o $(TARGET) $(LDFLAGS) $(OBJECTS) $(LOADLIBES) $(LDLIBS)
|
||||
#
|
||||
#clean:
|
||||
# $(RM) $(OBJECTS) $(TARGET)
|
||||
#
|
||||
#.PHONY: all clean
|
||||
|
||||
|
||||
#CC=gcc
|
||||
#CFLAGS=-c -Wall
|
||||
##LDFLAGS=
|
||||
##INCLUDES=-I.. ./inc
|
||||
##LIBS=-L. --llist
|
||||
#
|
||||
## all: standserver test_xmalloc
|
||||
#
|
||||
#all: xerror.o xmalloc.o
|
||||
#
|
||||
#standserver: standserver.o xmalloc.o
|
||||
# $(CC) $(CFLAGS) standserver.o xmalloc.o -o standserver
|
||||
#
|
||||
#xmalloc.o:
|
||||
# $(CC) $(CFLAGS) xmalloc.c
|
||||
#
|
||||
#xerror.o:
|
||||
# $(CC) $(CFLAGS) xerror.c
|
||||
#
|
||||
#clean:
|
||||
# rm -rf *.o *.gch standserver test_xmalloc
|
|
@ -7,12 +7,7 @@
|
|||
#include <sys/socket.h>
|
||||
#include <netinet/in.h>
|
||||
|
||||
unsigned int ip2int(const char *s)
|
||||
{
|
||||
int ip[4];
|
||||
sscanf(s, "%d.%d.%d.%d", ip, ip + 1, ip + 2, ip + 3);
|
||||
return ip[0] << 24 | ip[1] << 16 | ip[2] << 8 | ip[3];
|
||||
}
|
||||
#include "netfuncs.h"
|
||||
|
||||
int sendall(int s, char *buf, int len, int flags)
|
||||
{
|
||||
|
|
|
@ -11,18 +11,12 @@
|
|||
#include <fcntl.h>
|
||||
|
||||
#include "xerror.h"
|
||||
#include "netfuncs.h"
|
||||
|
||||
#define NUM_THREADS 8
|
||||
|
||||
pthread_mutex_t request_mutex = PTHREAD_MUTEX_INITIALIZER;
|
||||
|
||||
static const char *int2ip(unsigned int ip)
|
||||
{
|
||||
static char s[16];
|
||||
sprintf(s, "%d.%d.%d.%d", ip >> 24, ip << 8 >> 24, ip << 16 >> 24, ip << 24 >> 24);
|
||||
return s;
|
||||
}
|
||||
|
||||
void *serv_request(void *data)
|
||||
{
|
||||
struct connection_cb {
|
||||
|
@ -36,7 +30,7 @@ void *serv_request(void *data)
|
|||
|
||||
struct connection_cb *connections = NULL;
|
||||
|
||||
int listenSocket = (int)data;
|
||||
int listenSocket = *(int *)data;
|
||||
if (fcntl(listenSocket, F_SETFL, O_NONBLOCK) < 0)
|
||||
die("fcntl()", errno);
|
||||
|
||||
|
@ -103,7 +97,7 @@ void *serv_request(void *data)
|
|||
(*currentConnPtr)->dataToSend = result;
|
||||
(*currentConnPtr)->dataSent = 0;
|
||||
(*currentConnPtr)->isReading = 0;
|
||||
printf("Recieving as Slave Thread id = '%d' \n", pthread_self());
|
||||
printf("Recieving as Slave Thread id = '%d' \n", (int)pthread_self());
|
||||
}
|
||||
} else
|
||||
/*
|
||||
|
@ -133,7 +127,7 @@ void *serv_request(void *data)
|
|||
}
|
||||
|
||||
currentConnPtr = &((*currentConnPtr)->next);
|
||||
printf("Sending as Slave Thread id = '%d' \n", pthread_self());
|
||||
printf("Sending as Slave Thread id = '%d' \n", (int)pthread_self());
|
||||
}
|
||||
/*
|
||||
Проверка принадлежности дескриптора listenSocket
|
||||
|
@ -167,36 +161,13 @@ void *serv_request(void *data)
|
|||
(*currentConnPtr)->isReading = 1;
|
||||
(*currentConnPtr)->next = 0;
|
||||
currentConnPtr = &((*currentConnPtr)->next);
|
||||
printf("Accepting as Master Thread id = '%d' \n", pthread_self());
|
||||
printf("Accepting as Master Thread id = '%d' \n", (int)pthread_self());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//~ void *serv_request(void *data)
|
||||
//~ {
|
||||
//~ struct connection_cb
|
||||
//~ {
|
||||
//~ int dataSocket;
|
||||
//~ char data[256];
|
||||
//~ int dataSent;
|
||||
//~ int dataToSend;
|
||||
//~ int isRading;
|
||||
//~ struct connection_cb *next;
|
||||
//~ };
|
||||
//~
|
||||
//~ struct connection_cb *connections = NULL;
|
||||
//~
|
||||
//~ int listenSocket = (int)data;
|
||||
//~
|
||||
//~ if(fcntl(listenSocket, F_SETFL, O_NONBLOCK) < 0)
|
||||
//~ die("fcntl()", errno);
|
||||
//~
|
||||
//~
|
||||
//~
|
||||
//~ }
|
||||
|
||||
int getServerSocket(unsigned short int port)
|
||||
{
|
||||
int listenSocket;
|
||||
|
@ -245,7 +216,7 @@ int main(int argc, char *argv[])
|
|||
descSock = getServerSocket(atoi(service));
|
||||
|
||||
for (k = 0; k < NUM_THREADS; k++) {
|
||||
pthread_create(&p_thread[k], &attr, serv_request, (void *)descSock);
|
||||
pthread_create(&p_thread[k], &attr, serv_request, (void *)&descSock);
|
||||
printf("Thread %d started\n", k);
|
||||
}
|
||||
|
||||
|
|
|
@ -1,35 +0,0 @@
|
|||
#include <stdio.h>
|
||||
#include <errno.h>
|
||||
#include <stdlib.h>
|
||||
#include <unistd.h>
|
||||
|
||||
#include <sys/types.h>
|
||||
#include <sys/socket.h>
|
||||
#include <netinet/in.h>
|
||||
|
||||
#include <netinet/in.h>
|
||||
#include <arpa/inet.h>
|
||||
|
||||
#include <netdb.h>
|
||||
|
||||
static const char *int2ip(unsigned int ip)
|
||||
{
|
||||
static char s[16];
|
||||
sprintf(s, "%d.%d.%d.%d", ip >> 24, ip << 8 >> 24, ip << 16 >> 24, ip << 24 >> 24);
|
||||
return s;
|
||||
}
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
if (argc < 2) {
|
||||
perror("need hex ip address");
|
||||
exit(1);
|
||||
}
|
||||
|
||||
unsigned int ip = 0;
|
||||
sscanf(argv[1], "%X", &ip);
|
||||
|
||||
printf("%s\n", int2ip(ip));
|
||||
|
||||
return 0;
|
||||
}
|
|
@ -1,32 +0,0 @@
|
|||
#include <stdio.h>
|
||||
#include <errno.h>
|
||||
#include <stdlib.h>
|
||||
#include <unistd.h>
|
||||
|
||||
#include <sys/types.h>
|
||||
#include <sys/socket.h>
|
||||
#include <netinet/in.h>
|
||||
|
||||
#include <netinet/in.h>
|
||||
#include <arpa/inet.h>
|
||||
|
||||
#include <netdb.h>
|
||||
|
||||
unsigned int ip2int(const char *s)
|
||||
{
|
||||
int ip[4];
|
||||
sscanf(s, "%d.%d.%d.%d", ip, ip + 1, ip + 2, ip + 3);
|
||||
return ip[0] << 24 | ip[1] << 16 | ip[2] << 8 | ip[3];
|
||||
}
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
if (argc < 2) {
|
||||
perror("need ip address string");
|
||||
exit(1);
|
||||
}
|
||||
|
||||
printf("%X\n", ip2int(argv[1]));
|
||||
|
||||
return 0;
|
||||
}
|
|
@ -0,0 +1,24 @@
|
|||
|
||||
[indentation]
|
||||
indent_width=8
|
||||
indent_type=1
|
||||
indent_hard_tab_width=8
|
||||
detect_indent=false
|
||||
indent_mode=2
|
||||
|
||||
[project]
|
||||
name=masync_server
|
||||
base_path=/home/kolan/dev/c/masync_server/
|
||||
description=
|
||||
|
||||
[long line marker]
|
||||
long_line_behaviour=1
|
||||
long_line_column=72
|
||||
|
||||
[files]
|
||||
current_page=4
|
||||
FILE_NAME_0=5095;C;0;16;1;1;1;/home/kolan/dev/c/masync_server/echo-server.c;0
|
||||
FILE_NAME_1=173;C;0;16;1;1;1;/home/kolan/dev/c/masync_server/echo-client.c;0
|
||||
FILE_NAME_2=41;C;0;16;1;1;1;/home/kolan/dev/c/masync_server/netfuncs.c;0
|
||||
FILE_NAME_3=119;C;0;16;1;1;1;/home/kolan/dev/c/masync_server/netfuncs.h;0
|
||||
FILE_NAME_4=79;C;0;16;1;1;1;/home/kolan/dev/c/masync_server/xerror.c;0
|
|
@ -0,0 +1,17 @@
|
|||
#include "netfuncs.h"
|
||||
|
||||
#include <stdio.h>
|
||||
|
||||
unsigned int ip2int(const char *s)
|
||||
{
|
||||
int ip[4];
|
||||
sscanf(s, "%d.%d.%d.%d", ip, ip + 1, ip + 2, ip + 3);
|
||||
return ip[0] << 24 | ip[1] << 16 | ip[2] << 8 | ip[3];
|
||||
}
|
||||
|
||||
static const char *int2ip(unsigned int ip)
|
||||
{
|
||||
static char s[16];
|
||||
sprintf(s, "%d.%d.%d.%d", ip >> 24, ip << 8 >> 24, ip << 16 >> 24, ip << 24 >> 24);
|
||||
return s;
|
||||
}
|
|
@ -0,0 +1,8 @@
|
|||
#ifndef NETFUNCS_H
|
||||
#define NETFUNCS_H
|
||||
|
||||
unsigned int ip2int(const char *s);
|
||||
|
||||
static const char *int2ip(unsigned int ip);
|
||||
|
||||
#endif // NETFUNCS
|
|
@ -1,65 +0,0 @@
|
|||
#include <stdio.h>
|
||||
#include <sys/types.h>
|
||||
#include <sys/socket.h>
|
||||
|
||||
//~ domain = AF_UNIX, AF_INET, AF_INET6, AF_IPX
|
||||
//~ type = SOCK_STREAM, SOCK_DGRAM, SOCK_RAW
|
||||
//~ int socket(int domain, int type, int protocol);
|
||||
|
||||
//~ struct sockaddr {
|
||||
//~ unsigned short sa_family; // Семейство адресов, AF_xxx
|
||||
//~ char sa_data[14]; // 14 байтов для хранения адреса
|
||||
//~ };
|
||||
//~ struct sockaddr_in {
|
||||
//~ short int sin_family; // Семейство адресов
|
||||
//~ unsigned short int sin_port; // Номер порта
|
||||
//~ struct in_addr sin_addr; // IP-адрес
|
||||
//~ unsigned char sin_zero[8]; // "Дополнение" до размера структуры sockaddr
|
||||
//~ };
|
||||
//~ struct in_addr {
|
||||
//~ unsigned long s_addr;
|
||||
//~ };
|
||||
//~ htons, htonl, ntohs, ntohl
|
||||
//~ int bind(int sockfd, struct sockaddr *addr, int addrlen);
|
||||
|
||||
//~ int listen(int sockfd, int backlog);
|
||||
//~ int accept(int sockfd, void *addr, int *addrlen);
|
||||
|
||||
// клиент
|
||||
//~ int connect(int sockfd, struct sockaddr *serv_addr, int addrlen);
|
||||
|
||||
//~ int send(int sockfd, const void *msg, int len, int flags);
|
||||
|
||||
// отправка буфера целиком
|
||||
//~ int sendall(int s, char *buf, int len, int flags)
|
||||
//~ {
|
||||
//~ int total = 0;
|
||||
//~ int n;
|
||||
//~
|
||||
//~ while(total < len)
|
||||
//~ {
|
||||
//~ n = send(s, buf+total, len-total, flags);
|
||||
//~ if(n == -1) { break; }
|
||||
//~ total += n;
|
||||
//~ }
|
||||
//~
|
||||
//~ return (n==-1 ? -1 : total);
|
||||
//~ }
|
||||
|
||||
//~ int recv(int sockfd, void *buf, int len, int flags);
|
||||
|
||||
// закрытие соединения
|
||||
//~ int close(int fd);
|
||||
|
||||
// запрет передачи 0 - чтения, 1 - записи, 2 - и того, и др.
|
||||
//~ int shutdown(int sockfd, int how);
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
struct a {
|
||||
char aaa[256];
|
||||
};
|
||||
|
||||
printf("%lu\n", sizeof(struct a));
|
||||
return 0;
|
||||
}
|
|
@ -1,25 +0,0 @@
|
|||
#include <stdio.h>
|
||||
|
||||
void f()
|
||||
{
|
||||
int c = 0;
|
||||
printf("c=%lu\n", (unsigned long)&c);
|
||||
}
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
//~ printf("%lu\n", sizeof(long));
|
||||
|
||||
int a = 0;
|
||||
|
||||
int pid = fork();
|
||||
printf("pid=%d\n", pid);
|
||||
printf("a=%lu\n", (unsigned long)&a);
|
||||
|
||||
int b = 0;
|
||||
printf("b=%lu\n", (unsigned long)&b);
|
||||
|
||||
f();
|
||||
|
||||
return 0;
|
||||
}
|
|
@ -0,0 +1,17 @@
|
|||
#include "xerror.h"
|
||||
|
||||
#include <stdio.h>
|
||||
#include <errno.h>
|
||||
#include <string.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
void die(const char *func, int err)
|
||||
{
|
||||
fprintf(stderr, "%s: %s\n", func, strerror(err));
|
||||
abort();
|
||||
}
|
||||
|
||||
void bark(const char *func, int err)
|
||||
{
|
||||
fprintf(stderr, "%s: %s\n", func, strerror(err));
|
||||
}
|
|
@ -0,0 +1,8 @@
|
|||
#ifndef XERROR_H
|
||||
#define XERROR_H
|
||||
|
||||
void die(const char *func, int err);
|
||||
|
||||
void bark(const char *func, int err);
|
||||
|
||||
#endif // XERORR_H
|
Loading…
Reference in New Issue