Compare commits
2 Commits
62c116200c
...
38a094ff41
Author | SHA1 | Date | |
---|---|---|---|
|
38a094ff41 | ||
|
b7cbf73ce3 |
11
README.md
11
README.md
@ -7,13 +7,16 @@ To build source, you should install `build-essential`.
|
|||||||
Usage:
|
Usage:
|
||||||
```bash
|
```bash
|
||||||
./server [OPTION]...
|
./server [OPTION]...
|
||||||
./client SERVERNAME PORT FILENAME
|
./client SERVERNAME PORT [option] [FILENAME]...
|
||||||
```
|
```
|
||||||
|
|
||||||
Server OPTION and arguments:
|
Server OPTION and arguments:
|
||||||
- `-p port` :set to port binding. couldn't set to 0
|
- `-p port` :set to port binding. couldn't set to 0
|
||||||
- `-h` :print help message.
|
- `-h` :print help message.
|
||||||
|
|
||||||
|
Client option and arguments:
|
||||||
|
- `-b` :benchmark mode
|
||||||
|
|
||||||
Available macro:
|
Available macro:
|
||||||
|
|
||||||
For server
|
For server
|
||||||
@ -22,9 +25,9 @@ For server
|
|||||||
- DEFAULT_MAX_PATH_SIZE: 256(must be less than 1000)
|
- DEFAULT_MAX_PATH_SIZE: 256(must be less than 1000)
|
||||||
- USE_SENDFILE
|
- USE_SENDFILE
|
||||||
- DEFAULT_SEND_FILE_CHUNK_SIZE: 0x100000(1MB)
|
- DEFAULT_SEND_FILE_CHUNK_SIZE: 0x100000(1MB)
|
||||||
- DEFAULT_WORK_QUEUE_SIZE: 10
|
- DEFAULT_WORK_QUEUE_SIZE(server only): 10
|
||||||
- DEFAULT_MAX_THREAD_NUMBER: 10
|
- DEFAULT_MAX_THREAD_NUMBER(server only): 10
|
||||||
|
- DEFAULT_RESPONSE_REQUEST(p-server only): 3(-1 is INF)
|
||||||
For client
|
For client
|
||||||
- MUL_CLIENT(second unit)
|
- MUL_CLIENT(second unit)
|
||||||
- SLOW_CLIENT(microsecond unit, (buf_size/SLOW_CLIENT) bytes/usec)
|
- SLOW_CLIENT(microsecond unit, (buf_size/SLOW_CLIENT) bytes/usec)
|
||||||
|
68
client.c
68
client.c
@ -12,6 +12,9 @@
|
|||||||
#include <stdbool.h>
|
#include <stdbool.h>
|
||||||
#include <assert.h>
|
#include <assert.h>
|
||||||
#include <fcntl.h>
|
#include <fcntl.h>
|
||||||
|
#include <time.h>
|
||||||
|
#include <sys/time.h>
|
||||||
|
#include <sys/times.h>
|
||||||
#include "socket_wrapper.h"
|
#include "socket_wrapper.h"
|
||||||
|
|
||||||
#ifdef USE_SENDFILE
|
#ifdef USE_SENDFILE
|
||||||
@ -169,24 +172,33 @@ int main(int argc, const char *argv[]){
|
|||||||
const char * filename;
|
const char * filename;
|
||||||
const char * server_name;
|
const char * server_name;
|
||||||
in_port_t server_port = 0;
|
in_port_t server_port = 0;
|
||||||
|
int arg_filename_start = 3;
|
||||||
int sock, err;
|
int sock, err;
|
||||||
if (argc != 4){
|
int retval = 0;
|
||||||
fprintf(stderr,"USAUE: %s SERVERNAME PORT FILENAME\n",argv[0]);
|
bool benchmode = false;
|
||||||
|
|
||||||
|
clock_t clock_sum = 0;
|
||||||
|
clock_t begin_sclock;
|
||||||
|
clock_t begin_uclock;
|
||||||
|
|
||||||
|
int op_count = 0;
|
||||||
|
if (argc < 4){
|
||||||
|
fprintf(stderr,"USAUE: %s SERVERNAME PORT [Option]... [FILENAME]...\n",argv[0]);
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
server_name = argv[1];
|
server_name = argv[1];
|
||||||
server_port = atoi(argv[2]);
|
server_port = atoi(argv[2]);
|
||||||
filename = argv[3];
|
if (strcmp("-b",argv[arg_filename_start])==0
|
||||||
if (server_port == 0)
|
||strcmp("--benchmark",argv[arg_filename_start])==0){
|
||||||
{
|
arg_filename_start++;
|
||||||
|
benchmode = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (server_port == 0){
|
||||||
fprintf(stderr,"port invalid");
|
fprintf(stderr,"port invalid");
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
sock = socket(AF_INET,SOCK_STREAM,0);
|
|
||||||
if(sock < 0){
|
|
||||||
perror("sock create fail");
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
err = getsockaddrbyname(AF_INET,SOCK_STREAM,0,server_name,(struct sockaddr *)&addr);
|
err = getsockaddrbyname(AF_INET,SOCK_STREAM,0,server_name,(struct sockaddr *)&addr);
|
||||||
if (err != 0){
|
if (err != 0){
|
||||||
int check;
|
int check;
|
||||||
@ -196,21 +208,49 @@ int main(int argc, const char *argv[]){
|
|||||||
assert(check != -1);
|
assert(check != -1);
|
||||||
if (check == 0){
|
if (check == 0){
|
||||||
fprintf(stderr,"parsing fail : invaild format\n");
|
fprintf(stderr,"parsing fail : invaild format\n");
|
||||||
close(sock);
|
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
addr.sin_family = AF_INET;
|
addr.sin_family = AF_INET;
|
||||||
addr.sin_port = htons(server_port);
|
addr.sin_port = htons(server_port);
|
||||||
|
|
||||||
|
if (benchmode){
|
||||||
|
struct tms t;
|
||||||
|
times(&t);
|
||||||
|
begin_sclock = t.tms_stime;
|
||||||
|
begin_uclock = t.tms_utime;
|
||||||
|
}
|
||||||
|
while (arg_filename_start < argc){
|
||||||
|
filename = argv[arg_filename_start++];
|
||||||
|
sock = socket(AF_INET,SOCK_STREAM,0);
|
||||||
|
if(sock < 0){
|
||||||
|
perror("sock create fail");
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
if(connect(sock,(struct sockaddr *)&addr,sizeof(addr)) < 0){
|
if(connect(sock,(struct sockaddr *)&addr,sizeof(addr)) < 0){
|
||||||
perror("connect failed");
|
perror("connect failed");
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
if(sendReadOp(sock,filename) == 0){
|
if(sendReadOp(sock,filename) == 0){
|
||||||
int ret = recvData(sock,filename);
|
int ret = recvData(sock,filename);
|
||||||
close(sock);
|
if (ret < 0){
|
||||||
return ret;
|
fprintf(stderr,"%d",ret);
|
||||||
|
}
|
||||||
|
retval += ret;
|
||||||
}
|
}
|
||||||
close(sock);
|
close(sock);
|
||||||
return 0;
|
op_count++;
|
||||||
|
}
|
||||||
|
if (benchmode){
|
||||||
|
struct tms t;
|
||||||
|
times(&t);
|
||||||
|
clock_sum += t.tms_stime - begin_sclock;
|
||||||
|
clock_sum += t.tms_utime - begin_uclock;
|
||||||
|
}
|
||||||
|
if (benchmode){
|
||||||
|
fprintf(stdout,"operation: %lf ticks/op\n",((double)clock_sum)/((double)op_count));
|
||||||
|
}
|
||||||
|
|
||||||
|
return retval;
|
||||||
}
|
}
|
@ -12,7 +12,6 @@
|
|||||||
#include <stdbool.h>
|
#include <stdbool.h>
|
||||||
#include <assert.h>
|
#include <assert.h>
|
||||||
#include <fcntl.h>
|
#include <fcntl.h>
|
||||||
|
|
||||||
#include "socket_wrapper.h"
|
#include "socket_wrapper.h"
|
||||||
|
|
||||||
#ifdef USE_SENDFILE
|
#ifdef USE_SENDFILE
|
||||||
|
13
p-server.c
13
p-server.c
@ -15,7 +15,11 @@
|
|||||||
#include <sys/wait.h>
|
#include <sys/wait.h>
|
||||||
#include "socket_wrapper.h"
|
#include "socket_wrapper.h"
|
||||||
|
|
||||||
|
#ifndef DEFAULT_MAX_LISTEN_SOCKET
|
||||||
static const int MAX_LISTEN_SOCKET = 16;
|
static const int MAX_LISTEN_SOCKET = 16;
|
||||||
|
#else
|
||||||
|
static const int MAX_LISTEN_SOCKET = DEFAULT_MAX_LISTEN_SOCKET;
|
||||||
|
#endif
|
||||||
|
|
||||||
#ifdef USE_SENDFILE
|
#ifdef USE_SENDFILE
|
||||||
#include <sys/sendfile.h>
|
#include <sys/sendfile.h>
|
||||||
@ -41,6 +45,11 @@ static const int TIMEOUT = 5;
|
|||||||
#else
|
#else
|
||||||
static const int TIMEOUT = DEFAULT_TIMEOUT;
|
static const int TIMEOUT = DEFAULT_TIMEOUT;
|
||||||
#endif
|
#endif
|
||||||
|
#ifndef DEFAULT_RESPONSE_REQUEST
|
||||||
|
static const int RESPONSE_REQUEST = 3;
|
||||||
|
#else
|
||||||
|
static const int RESPONSE_REQUEST = DEFAULT_RESPONSE_REQUEST;
|
||||||
|
#endif
|
||||||
|
|
||||||
/*========
|
/*========
|
||||||
*Operation
|
*Operation
|
||||||
@ -261,7 +270,7 @@ int main(int argc, const char *argv[]){
|
|||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
for (i = 0; i < 3; i++)
|
for (i = 0; i < RESPONSE_REQUEST; i++)
|
||||||
{
|
{
|
||||||
int fd, pid;
|
int fd, pid;
|
||||||
char ip_buf[INET_ADDRSTRLEN];
|
char ip_buf[INET_ADDRSTRLEN];
|
||||||
@ -287,7 +296,7 @@ int main(int argc, const char *argv[]){
|
|||||||
return retval;
|
return retval;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
for (i = 0; i < 3; i++)
|
for (i = 0; i < RESPONSE_REQUEST; i++)
|
||||||
{
|
{
|
||||||
int retval;
|
int retval;
|
||||||
int pid = wait(&retval);
|
int pid = wait(&retval);
|
||||||
|
Loading…
Reference in New Issue
Block a user