FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
CSNode/Server2.cpp at main · elfpipe/CSNode · GitHub
elfpipe
CSNode
Repository navigation
Code
Issues
Pull requests
Actions
Projects
Security and quality
Insights
Expand file tree
Breadcrumbs
CSNode
/
Server2.cpp
Copy path
More file actions
More file actions
Latest commit
History
History
History
62 lines (53 loc) · 1.69 KB
Breadcrumbs
CSNode
/
Server2.cpp
Copy path
File metadata and controls
62 lines (53 loc) · 1.69 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
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
#
include
<
unistd.h
>
#
include
<
poll.h
>
#
include
<
iostream
>
#
include
<
strings.h
>
#
include
"
CSNode.hpp
"
#
include
"
Server.hpp
"
Server::Server
(CSNode *node) {
this
->
node
= node;
}
void
Server::startThread
() {
pthread_t
threadHandle;
pipe
(exitPipe);
pthread_create
(&threadHandle,
0
, thread, (
void
*)
this
);
}
#
define
MAX
(
x,y
) ((x) < (y) ? (y) : (x))
void
*
Server::thread
(
void
*dummy) {
Server *_this = (Server *) dummy;
fd_set rfds;
struct
timeval
tv;
int
retval;
while
(
1
) {
FD_ZERO
(&rfds);
FD_SET
(_this->
node
->
bindSocket
, &rfds);
FD_SET
(_this->
exitPipe
[
0
], &rfds);
int
maxfd =
MAX
(_this->
node
->
bindSocket
, _this->
exitPipe
[
0
]);
tv.
tv_sec
=
5
;
tv.
tv_usec
=
0
;
retval =
select
(maxfd+
1
, &rfds,
0
,
0
, &tv);
if
(retval <
0
) {
perror
(
"
select
"
);
pthread_exit
(
0
);
}
if
(
FD_ISSET
(_this->
node
->
bindSocket
, &rfds)) {
cout <<
"
Incomming call...
\n
"
;
CSNode::CSConnection *connection = _this->
node
->
waitForIncomming
(_this->
node
->
port
);
if
(connection) {
//
cout << "<message> : " << _this->node->readSentence (connection, '\3') << "\n";
//
_this->node->writeSentence (connection, "CLOSE");
_this->
node
->
serverCommand
(connection);
_this->
node
->
closeConnection
(connection);
cout <<
"
Call completed.
\n
"
;
_this->
endThread
();
}
}
if
(
FD_ISSET
(_this->
exitPipe
[
0
], &rfds)) {
cout <<
"
exitPipe activatet (EXIT)
\n
"
;
pthread_exit
(
0
);
}
}
}
void
Server::endThread
() {
write
(exitPipe[
1
],
"
hej
\0
"
,
4
);
}
Back
|
FazBrowse Home
|
New Git URL