Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
S
semmodbus-server
Manage
Activity
Members
Labels
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Deploy
Releases
Model registry
Analyze
Value stream analytics
Contributor analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Kiss Ádám
semmodbus-server
Commits
921c9409
Commit
921c9409
authored
Apr 18, 2017
by
SEMuser
Browse files
Options
Downloads
Patches
Plain Diff
Memory leak fixed, at creating server threads.
By Kiss Adam
parent
0150bc0d
Branches
Branches containing commit
No related tags found
No related merge requests found
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
.gitignore
+1
-0
1 addition, 0 deletions
.gitignore
devices/jelenletjelzo.cpp
+3
-3
3 additions, 3 deletions
devices/jelenletjelzo.cpp
socket_listener.cpp
+3
-4
3 additions, 4 deletions
socket_listener.cpp
with
7 additions
and
7 deletions
.gitignore
+
1
−
0
View file @
921c9409
semmodbus
semmodbus
semmodbus_server.layout
This diff is collapsed.
Click to expand it.
devices/jelenletjelzo.cpp
+
3
−
3
View file @
921c9409
...
@@ -4,15 +4,15 @@ void jelenletjelzo::poll(modbus_t* modbus){
...
@@ -4,15 +4,15 @@ void jelenletjelzo::poll(modbus_t* modbus){
modbus_flush
(
modbus
);
//Flush modbus buffers
modbus_flush
(
modbus
);
//Flush modbus buffers
modbus_set_slave
(
modbus
,
1
);
//Set slave address to 1
modbus_set_slave
(
modbus
,
1
);
//Set slave address to 1
uint16_t
asd
;
uint16_t
buff
;
if
(
modbus_read_input_registers
(
modbus
,
0x00
,
1
,
&
asd
)
==
-
1
)
{
//read 1 (third arg) input register, from register index 0(sec arg), to
the address of asd
if
(
modbus_read_input_registers
(
modbus
,
0x00
,
1
,
&
buff
)
==
-
1
)
{
//read 1 (third arg) input register, from register index 0(sec arg), to
buff
fprintf
(
stderr
,
"Error %d while reading: %s
\n
"
,
errno
,
modbus_strerror
(
errno
));
fprintf
(
stderr
,
"Error %d while reading: %s
\n
"
,
errno
,
modbus_strerror
(
errno
));
return
;
return
;
}
}
m
.
lock
();
//lock semaphore
m
.
lock
();
//lock semaphore
stat
=
asd
&
(
1
<<
7
);
//set stat
stat
=
buff
&
(
1
<<
7
);
//set stat
m
.
unlock
();
//unlock
m
.
unlock
();
//unlock
}
}
...
...
This diff is collapsed.
Click to expand it.
socket_listener.cpp
+
3
−
4
View file @
921c9409
...
@@ -49,7 +49,7 @@ void serveConnect(Socket s){
...
@@ -49,7 +49,7 @@ void serveConnect(Socket s){
for
(
auto
*
i
:
Devices
){
for
(
auto
*
i
:
Devices
){
if
(
i
->
getName
()
==
req_device
){
if
(
i
->
getName
()
==
req_device
){
found
=
true
;
found
=
true
;
std
::
stringstream
ss
;
///TODO: clea
r
the code, skip stringstream
std
::
stringstream
ss
;
///TODO: clea
n
the code, skip stringstream
ss
<<
i
->
getResp
(
json_request
);
ss
<<
i
->
getResp
(
json_request
);
std
::
string
ans
=
ss
.
str
();
std
::
string
ans
=
ss
.
str
();
...
@@ -91,8 +91,6 @@ void SocketListener(){
...
@@ -91,8 +91,6 @@ void SocketListener(){
std
::
cout
<<
"Socket Listener thread started
\n\n
"
;
std
::
cout
<<
"Socket Listener thread started
\n\n
"
;
std
::
set_terminate
(
socket_thread_terminator
);
std
::
set_terminate
(
socket_thread_terminator
);
std
::
list
<
std
::
thread
*>
Connects
;
int
portno
;
int
portno
;
Socket
accpeted
;
Socket
accpeted
;
socklen_t
clilen
;
socklen_t
clilen
;
...
@@ -126,6 +124,7 @@ void SocketListener(){
...
@@ -126,6 +124,7 @@ void SocketListener(){
if
(
accpeted
<
0
)
{
if
(
accpeted
<
0
)
{
perror
(
"ERROR on accept"
);
perror
(
"ERROR on accept"
);
}
}
Connects
.
push_back
(
new
std
::
thread
(
serveConnect
,
accpeted
));
///TODO: fix memory leak
std
::
thread
serving_thread
(
serveConnect
,
accpeted
);
serving_thread
.
detach
();
}
}
}
}
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