stephane / libmodbus

A Modbus library for Linux, Mac OS, FreeBSD and Windows
http://libmodbus.org
GNU Lesser General Public License v2.1
3.33k stars 1.71k forks source link

Need to clone modbus_t TCP context #47

Closed Fred-Spreen-Logikos closed 11 years ago

Fred-Spreen-Logikos commented 12 years ago

In order to create a multi-threaded TCP server, it is necessary to duplicate the modbus_t TCP context, but no function currently exists to do this. Additionally, the modbus_t structure points to connection-specific data, so a simple memcpy() doesn't do the job.

Below is a patch which provides the appropriate functions.

diff -r a/libmodbus/src/modbus-tcp.c b/libmodbus/src/modbus-tcp.c --- a/libmodbus/src/modbus-tcp.c +++ b/libmodbus/src/modbus-tcp.c @@ -732,3 +732,19 @@

 return ctx;

} + +void modbus_clone_tcp(modbus_t* new_ctx, modbus_t* ctx) +{

stephane commented 12 years ago

Once you've copied the structure it doesn't allow you to share the same socket between your threads. Could you explain your use case?

stephane commented 11 years ago

No answer...