Skip to content

Commit 103b920

Browse files
committed
src/modbus-tcp.c: modbus_tcp_listen(): clarify failed TCP listener situations
Signed-off-by: Jim Klimov <jimklimov@gmail.com>
1 parent f2ea473 commit 103b920

File tree

1 file changed

+10
-0
lines changed

1 file changed

+10
-0
lines changed

src/modbus-tcp.c

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -758,6 +758,8 @@ int modbus_tcp_listen(modbus_t *ctx, int nb_connection)
758758

759759
#ifdef OS_WIN32
760760
if (_modbus_tcp_init_win32() == -1) {
761+
if (ctx->debug)
762+
perror("_modbus_tcp_init_win32");
761763
return -1;
762764
}
763765
#endif
@@ -770,11 +772,15 @@ int modbus_tcp_listen(modbus_t *ctx, int nb_connection)
770772

771773
new_s = socket(PF_INET, flags, IPPROTO_TCP);
772774
if (new_s == -1) {
775+
if (ctx->debug)
776+
perror("socket");
773777
return -1;
774778
}
775779

776780
enable = 1;
777781
if (setsockopt(new_s, SOL_SOCKET, SO_REUSEADDR, (const void *)&enable, sizeof(enable)) == -1) {
782+
if (ctx->debug)
783+
perror("setsockopt");
778784
close(new_s);
779785
return -1;
780786
}
@@ -799,11 +805,15 @@ int modbus_tcp_listen(modbus_t *ctx, int nb_connection)
799805
}
800806

801807
if (bind(new_s, (struct sockaddr *) &addr, sizeof(addr)) == -1) {
808+
if (ctx->debug)
809+
perror("bind");
802810
close(new_s);
803811
return -1;
804812
}
805813

806814
if (listen(new_s, nb_connection) == -1) {
815+
if (ctx->debug)
816+
perror("listen");
807817
close(new_s);
808818
return -1;
809819
}

0 commit comments

Comments
 (0)