FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
CSNode/Server.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
/
Server.cpp
Copy path
More file actions
More file actions
Latest commit
History
History
History
49 lines (44 loc) · 1.39 KB
Breadcrumbs
CSNode
/
Server.cpp
Copy path
File metadata and controls
49 lines (44 loc) · 1.39 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
#
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
);
}
void
*
Server::thread
(
void
*dummy) {
Server *_this = (Server *) dummy;
struct
pollfd
pfds[
2
];
pfds[
0
] = {_this->
node
->
bindSocket
,
POLLIN
,
0
};
pfds[
1
] = {_this->
exitPipe
[
0
],
POLLIN
,
0
};
while
(
1
) {
if
(
poll
(pfds,
2
,
100
) <
0
) {
perror
(
"
poll
"
);
pthread_exit
(
0
);
}
if
(pfds[
0
].
revents
&
POLLIN
) {
cout <<
"
Icomming 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
"
;
}
}
if
(pfds[
1
].
revents
&
POLLIN
) {
cout <<
"
exitPipe activatet (EXIT)
\n
"
;
pthread_exit
(
0
);
}
}
}
void
Server::endThread
() {
write
(exitPipe[
1
],
"
hej
\0
"
,
4
);
}
Back
|
FazBrowse Home
|
New Git URL