Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adding TCP server handling to libmodbus #610

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ tests/random-test-server
tests/unit-test-client
tests/unit-test.h
tests/unit-test-server
tests/tcp-server-test
tests/version
tests/stamp-h2
doc/*.html
Expand Down
6 changes: 5 additions & 1 deletion doc/Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,11 @@ TXT3 = \
modbus_write_bits.txt \
modbus_write_bit.txt \
modbus_write_registers.txt \
modbus_write_register.txt
modbus_write_register.txt \
modbus_tcp_server_start.txt \
modbus_tcp_server_stop.txt \
modbus_tcp_server_handle.txt \
modbus_tcp_server_set_select_timeout.txt
TXT7 = libmodbus.txt

EXTRA_DIST = asciidoc.conf $(TXT3) $(TXT7)
Expand Down
38 changes: 38 additions & 0 deletions doc/modbus_tcp_server_handle.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
modbus_tcp_server_handle(3)
===========================


NAME
----
modbus_tcp_server_handle - handle data exchange on a modbus context


SYNOPSIS
--------
*int modbus_tcp_server_handle(modbus_tcp_server_t* mb_srv_ctx, modbus_mapping_t* mb_map);*


DESCRIPTION
-----------
The *modbus_tcp_server_handle()* function exchanges data with connected clients
based on the supplied _mb_map_ data structure.

Uses a select that defaults to BLOCKING, but that can be changed with
*modbus_tcp_server_set_select_timeout()*.


RETURN VALUE
------------
The function shall return 0 if successful. Otherwise it shall return -1 and set
errno.


SEE ALSO
--------
linkmb:modbus_server_create[3]
linkmb:modbus_server_destroy[3]


AUTHORS
-------
The libmodbus server documentation was written by DEIF A/S
32 changes: 32 additions & 0 deletions doc/modbus_tcp_server_set_select_timeout.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
modbus_tcp_server_set_select_timeout(3)
=======================================


NAME
----
modbus_tcp_server_set_select_timeout - set the idle timeout for each client.


SYNOPSIS
--------
*int modbus_tcp_server_set_select_timeout(modbus_tcp_server_t* mb_srv_ctx, uint32_t to_sec, uint32_t to_usec);*


DESCRIPTION
-----------
The *modbus_tcp_server_set_select_timeout()* changes the select timeout for
*modbus_server_handle()*.

Default the select is BLOCKING but with this you can set a timeout so
*modbus_server_handle()* returns within the specified time.


RETURN VALUE
------------
The function shall return 0 if successful. Otherwise it shall return -1 and set
errno.


AUTHORS
-------
The libmodbus server documentation was written by DEIF A/S
36 changes: 36 additions & 0 deletions doc/modbus_tcp_server_start.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
modbus_tcp_server_start(3)
==========================


NAME
----
modbus_tcp_server_start - create a tcp modbus server context


SYNOPSIS
--------
*modbus_tcp_server_t* modbus_tcp_server_start(char* ipaddr, uint16_t port, uint16_t max_connections);*


DESCRIPTION
-----------
The *modbus_tcp_server_start()* function shall prepare a context for a
standard modbus tcp server on _port_ with suport for max
_max_connections_ simultainious connections.


RETURN VALUE
------------
The function shall return a context for the modbus server if successful.
Otherwise it shall return NULL and set errno.


SEE ALSO
--------
linkmb:modbus_server_destroy[3]
linkmb:modbus_server_handle[3]


AUTHORS
-------
The libmodbus server documentation was written by DEIF A/S
39 changes: 39 additions & 0 deletions doc/modbus_tcp_server_stop.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
modbus_tcp_server_stop(3)
=========================


NAME
----
modbus_tcp_server_stop - destroy a tcp modbus server context


SYNOPSIS
--------
*int modbus_tcp_server_stop(modbus_tcp_server_t* mb_srv_ctx);*


DESCRIPTION
-----------
The *modbus_tcp_server_stop()* function shall set a shutdown flag
which is processed by modbus_server_handle.

This causes modbus_server_handle to free all context allocated with
*modbus_tcp_server_create()*, and closes all currently connected
modbus clients.


RETURN VALUE
------------
The function shall return 0 if successful. Otherwise it shall return -1 and set
errno


SEE ALSO
--------
linkmb:modbus_server_create[3]
linkmb:modbus_server_handle[3]


AUTHORS
-------
The libmodbus server documentation was written by DEIF A/S
6 changes: 4 additions & 2 deletions src/Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,9 @@ libmodbus_la_SOURCES = \
modbus-tcp.c \
modbus-tcp.h \
modbus-tcp-private.h \
modbus-version.h
modbus-version.h \
modbus-tcp-server.c \
modbus-tcp-server.h

libmodbus_la_LDFLAGS = -no-undefined \
-version-info $(LIBMODBUS_LT_VERSION_INFO)
Expand All @@ -35,7 +37,7 @@ endif

# Header files to install
libmodbusincludedir = $(includedir)/modbus
libmodbusinclude_HEADERS = modbus.h modbus-version.h modbus-rtu.h modbus-tcp.h
libmodbusinclude_HEADERS = modbus.h modbus-version.h modbus-rtu.h modbus-tcp.h modbus-tcp-server.h

DISTCLEANFILES = modbus-version.h
EXTRA_DIST += modbus-version.h.in
Expand Down
Loading