Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
L
libdap-server-core
Manage
Activity
Members
Labels
Plan
Issues
0
Issue boards
Milestones
Wiki
Code
Merge requests
0
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package Registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
This is an archived project. Repository and other project resources are read-only.
Show more breadcrumbs
cellframe
libdap-server-core
Commits
d1a59808
Commit
d1a59808
authored
6 years ago
by
armatusmiles
Browse files
Options
Downloads
Patches
Plain Diff
[+] buf_in/out_totals and calculate speed
parent
e3dd1325
No related branches found
No related tags found
No related merge requests found
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
dap_server.c
+5
-3
5 additions, 3 deletions
dap_server.c
dap_server_client.h
+10
-0
10 additions, 0 deletions
dap_server_client.h
dap_traffic_track.c
+47
-12
47 additions, 12 deletions
dap_traffic_track.c
dap_traffic_track.h
+2
-6
2 additions, 6 deletions
dap_traffic_track.h
with
64 additions
and
21 deletions
dap_server.c
+
5
−
3
View file @
d1a59808
...
...
@@ -52,7 +52,7 @@
#define LOG_TAG "dap_server"
static
void
read_write_cb
(
struct
ev_loop
*
loop
,
struct
ev_io
*
watcher
,
int
revents
);
static
void
read_write_cb
(
struct
ev_loop
*
_
loop
,
struct
ev_io
*
watcher
,
int
revents
);
static
struct
ev_loop
*
listener_clients_loop
;
static
ev_async
async_watcher
;
...
...
@@ -153,8 +153,9 @@ static void read_write_cb (struct ev_loop* loop, struct ev_io* watcher, int reve
0
);
if
(
bytes_read
>
0
)
{
dap_cur
->
buf_in_size_total
+=
bytes_read
;
dap_cur
->
buf_in_size
+=
bytes_read
;
sh
->
client_read_callback
(
dap_cur
,
NULL
);
sh
->
client_read_callback
(
dap_cur
,
NULL
);
}
else
if
(
bytes_read
<
0
)
{
...
...
@@ -186,11 +187,12 @@ static void read_write_cb (struct ev_loop* loop, struct ev_io* watcher, int reve
dap_cur
->
buf_out_size
-
total_sent
,
MSG_DONTWAIT
|
MSG_NOSIGNAL
);
if
(
bytes_sent
<
0
)
{
log_it
(
L_ERROR
,
"Some error occured in send() function"
);
log_it
(
L_ERROR
,
"Some error occured in send() function"
);
break
;
}
total_sent
+=
bytes_sent
;
}
dap_cur
->
buf_out_size_total
+=
dap_cur
->
buf_out_size
;
dap_cur
->
buf_out_size
=
0
;
}
}
...
...
This diff is collapsed.
Click to expand it.
dap_server_client.h
+
10
−
0
View file @
d1a59808
...
...
@@ -44,15 +44,25 @@ typedef struct dap_server_client{
uint32_t
buf_out_zero_count
;
char
buf_in
[
DAP_CLIENT_REMOTE_BUF
+
1
];
// Internal buffer for input data
size_t
buf_in_size
;
// size of data that is in the input buffer
size_t
buf_in_size_total_old
;
size_t
buf_in_size_total
;
double
upload_speed_bytes
;
// fills if module dap_traffic_track initialized
char
buf_out
[
DAP_CLIENT_REMOTE_BUF
+
1
];
// Internal buffer for output data
char
hostaddr
[
1024
];
// Address
char
service
[
128
];
size_t
buf_out_size
;
// size of data that is in the output buffer
size_t
buf_out_size_total_old
;
size_t
buf_out_size_total
;
double
download_speed_bytes
;
// fills if module dap_traffic_track initialized
ev_io
*
watcher_client
;
struct
dap_server
*
server
;
...
...
This diff is collapsed.
Click to expand it.
dap_traffic_track.c
+
47
−
12
View file @
d1a59808
...
...
@@ -2,35 +2,70 @@
#include
"dap_common.h"
#define LOG_TAG "dap_traffic_track"
#define BYTES_IN_MB 1048576.0
static
dap_traffic_callback_t
callback
=
NULL
;
static
dap_server_
client_t
*
server_clients
;
static
ev_timer
timeout_watcher
;
static
dap_server_
t
*
_dap_server
;
static
ev_timer
_
timeout_watcher
;
static
struct
ev_loop
*
loop
;
/**
* @brief calculate_mbs_speed
* @param count_bytes
* @details timeout we gots from _timeout_watcher.repeat
* @return mbs speed
*/
static
double
calculate_mbs_speed
(
size_t
count_bytes
)
{
size_t
bytes_per_sec
=
count_bytes
/
(
size_t
)
_timeout_watcher
.
repeat
;
log_it
(
L_DEBUG
,
"TIMEOUT: %d, bytes_per_sec: %d"
,
(
size_t
)
_timeout_watcher
.
repeat
,
bytes_per_sec
);
return
bytes_per_sec
/
BYTES_IN_MB
;
}
static
void
timeout_cb
()
{
if
(
callback
!=
NULL
)
{
callback
(
NULL
,
0
);
return
;
pthread_mutex_lock
(
&
_dap_server
->
mutex_on_hash
);
dap_server_client_t
*
dap_cur
,
*
tmp
;
HASH_ITER
(
hh
,
_dap_server
->
clients
,
dap_cur
,
tmp
)
{
log_it
(
L_DEBUG
,
"hash iter socket: %d buf_in_total_new: %d, buf_in_total_old: %d"
,
dap_cur
->
socket
,
dap_cur
->
buf_in_size_total
,
dap_cur
->
buf_in_size_total_old
);
dap_cur
->
upload_speed_bytes
=
calculate_mbs_speed
(
dap_cur
->
buf_in_size_total
-
dap_cur
->
buf_in_size_total_old
);
dap_cur
->
buf_in_size_total_old
=
dap_cur
->
buf_in_size_total
;
dap_cur
->
download_speed_bytes
=
calculate_mbs_speed
(
dap_cur
->
buf_out_size_total
-
dap_cur
->
buf_out_size_total_old
);
dap_cur
->
buf_out_size_total_old
=
dap_cur
->
buf_out_size_total
;
log_it
(
L_DEBUG
,
"upload_mbs: %f, download_mbs: %f"
,
dap_cur
->
upload_speed_bytes
,
dap_cur
->
download_speed_bytes
);
}
log_it
(
L_WARNING
,
"Callback is NULL!"
);
pthread_mutex_unlock
(
&
_dap_server
->
mutex_on_hash
);
// if(callback != NULL) {
// callback(NULL, 0);
// return;
// }
// log_it(L_WARNING, "Callback is NULL!");
}
void
dap_traffic_track_init
(
dap_server_
client_t
*
clients
,
void
dap_traffic_track_init
(
dap_server_
t
*
server
,
time_t
timeout
)
{
server
_clients
=
clients
;
timeout_watcher
.
repeat
=
timeout
;
_dap_
server
=
server
;
_
timeout_watcher
.
repeat
=
timeout
;
loop
=
EV_DEFAULT
;
ev_init
(
&
timeout_watcher
,
timeout_cb
);
ev_timer_again
(
loop
,
&
timeout_watcher
);
ev_init
(
&
_
timeout_watcher
,
timeout_cb
);
ev_timer_again
(
loop
,
&
_
timeout_watcher
);
log_it
(
L_NOTICE
,
"Initialized traffic track module"
);
}
void
dap_traffic_track_deinit
()
{
ev_timer_stop
(
loop
,
&
timeout_watcher
);
ev_timer_stop
(
loop
,
&
_
timeout_watcher
);
log_it
(
L_NOTICE
,
"Deinitialized traffic track module"
);
}
...
...
This diff is collapsed.
Click to expand it.
dap_traffic_track.h
+
2
−
6
View file @
d1a59808
#ifndef _TRAFFIC_TRACK_H_
#define _TRAFFIC_TRACK_H_
#include
"dap_server_client.h"
typedef
struct
dap_traffic_info
{
dap_server_client_t
*
client
;
size_t
traffic_speed_bytes
;
}
dap_traffic_info_t
;
#include
"dap_server.h"
typedef
void
(
*
dap_traffic_callback_t
)
(
struct
dap_traffic_info
*
,
size_t
count_info
);
// Callback for specific server's operations
...
...
@@ -14,7 +10,7 @@ typedef void (*dap_traffic_callback_t) (struct dap_traffic_info *, size_t count_
* @param clients
* @param timeout callback
*/
void
dap_traffic_track_init
(
dap_server_
client_t
*
clients
,
void
dap_traffic_track_init
(
dap_server_
t
*
server
,
time_t
timeout
);
/**
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment