-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.c
More file actions
73 lines (60 loc) · 1.61 KB
/
main.c
File metadata and controls
73 lines (60 loc) · 1.61 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
#include <stdio.h>
#include <pthread.h>
#include <unistd.h>
#include <string.h>
#include <netinet/in.h>
#include <arpa/inet.h>
// The USS Library
#include "include/uss.h"
/**
* Test config
*/
#define CONFIG_TEST_PORT 10088
#define CONFIG_TEST_SERVER "127.0.0.1"
#define CONFIG_TEST_LINK_MODE USS_LINK_TYPE_SOFTWARE
/**************************************
* Global test data
**************************************/
struct running_stat
{
unsigned long send, recv;
} run_stat;
static uss_instance_t uss;
/**************************************
* Running thread
**************************************/
static void *server_test_thread(void *arg)
{
return NULL;
}
static void *client_test_thread(void *arg)
{
struct sockaddr_in addr;
memset(&addr, 0, sizeof(addr));
addr.sin_port = CONFIG_TEST_PORT;
addr.sin_addr.s_addr = inet_addr(CONFIG_TEST_SERVER);
uss_connection_create(uss, (struct sockaddr*)&addr, CONFIG_TEST_LINK_MODE);
return NULL;
}
static void show_statistic()
{
uss_instance_t uss = uss_create();
printf("Running stat:\n");
printf(" send bytes %lu", run_stat.send);
memset(&run_stat, 0, sizeof(run_stat));
}
int main() {
pthread_t thread_srv, thread_cli;
// Step1, the instance
uss = uss_create();
// Step2, the test thread to make offload
printf("Hello, Let's create a server with USS.\n");
pthread_create(&thread_srv, NULL, server_test_thread, NULL);
pthread_create(&thread_cli, NULL, client_test_thread, NULL);
// Statistic
while (1) {
sleep(1);
show_statistic();
}
return 0;
}