{"action":"opened","issue":{"url":"https://api.github.com/repos/mz-automation/libiec61850/issues/66","repository_url":"https://api.github.com/repos/mz-automation/libiec61850","labels_url":"https://api.github.com/repos/mz-automation/libiec61850/issues/66/labels{/name}","comments_url":"https://api.github.com/repos/mz-automation/libiec61850/issues/66/comments","events_url":"https://api.github.com/repos/mz-automation/libiec61850/issues/66/events","html_url":"https://github.com/mz-automation/libiec61850/issues/66","id":329273242,"node_id":"MDU6SXNzdWUzMjkyNzMyNDI=","number":66,"title":"Embedded environment, multi-client connection, system deadlock.","user":{"login":"xuwei2015","id":14286054,"node_id":"MDQ6VXNlcjE0Mjg2MDU0","avatar_url":"https://avatars0.githubusercontent.com/u/14286054?v=4","gravatar_id":"","url":"https://api.github.com/users/xuwei2015","html_url":"https://github.com/xuwei2015","followers_url":"https://api.github.com/users/xuwei2015/followers","following_url":"https://api.github.com/users/xuwei2015/following{/other_user}","gists_url":"https://api.github.com/users/xuwei2015/gists{/gist_id}","starred_url":"https://api.github.com/users/xuwei2015/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/xuwei2015/subscriptions","organizations_url":"https://api.github.com/users/xuwei2015/orgs","repos_url":"https://api.github.com/users/xuwei2015/repos","events_url":"https://api.github.com/users/xuwei2015/events{/privacy}","received_events_url":"https://api.github.com/users/xuwei2015/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":0,"created_at":"2018-06-05T01:47:58Z","updated_at":"2018-06-05T01:47:58Z","closed_at":null,"author_association":"NONE","body":"Problem description:\r\nI used ieclib61850 1.2.1 to run the server in an embedded Linux environment (arm bigendian). The first client can connect normally. Connect to the second client and the system will deadlock (the console will not respond). At this point, disconnect the first client, the second client will be immediately connected, and the system will return to normal.\r\n\r\nConfiguration:\r\nStack_config.h adds a macro definition of the bigendian:\r\n`# define PLATFORM_IS_BIGENDIAN 1`\r\n\r\nThe rest are default and unchanged. The key parts are as follows:\r\n```\r\n/* Maximum MMS PDU SIZE - default is 65000 */\r\n# define CONFIG_MMS_MAXIMUM_PDU_SIZE 120000\r\n\r\n/ *\r\n* Enable single threaded mode\r\n*\r\n* 1 ==> server runs in single threaded mode (a single thread for the server and all client connections)\r\n* 0 => server runs in multi-threaded mode (one thread for each connection and)\r\n* one server background thread)\r\n* /\r\n# define CONFIG_MMS_SINGLE_THREADED 0\r\n\r\n/ *\r\n* Optimize stack for threadless oper-don't semt use aphores\r\n*\r\n* WARNING: If set to 1 normal single- and multi-threaded server are no longer working!\r\n* /\r\n# define CONFIG_MMS_THREADLESS_STACK 0\r\n\r\n/* number of concurrent MMS client connections the server accepts, -1 for no limit */\r\n# define CONFIG_MAXIMUM_TCP_CLIENT_CONNECTIONS 5\r\n\r\n/* activate TCP keep alive mechanism. 1-> activate */\r\n# define CONFIG_ACTIVATE_TCP_KEEPALIVE 1\r\n\r\n/* time (in s) between last message and first keepalive message */\r\n# define CONFIG_TCP_KEEPALIVE_IDLE 5\r\n\r\nAfter that, we kept alive messages if no ack received */\r\n# define CONFIG_TCP_KEEPALIVE_INTERVAL 2\r\n\r\n/* number of not missing keepalive responses until socket is considered dead */\r\n# define CONFIG_TCP_KEEPALIVE_CNT 2\r\n\r\n/* maximum COTP (ISO 8073) TPDU size-valid range is 1024-8192 */\r\n# define CONFIG_COTP_MAX_TPDU_SIZE 8192\r\n\r\n/* timeout while reading from TCP stream in ms */\r\n# define CONFIG_TCP_READ_TIMEOUT_MS 1000\r\n\r\n/* Ethernet interface ID for GOOSE and SV */\r\n# define CONFIG_ETHERNET_INTERFACE_ID \"eth0\"\r\n```\r\n\r\nCause analysis:\r\nI compared the debug print for the first and second client connections and found that the Socket_read function always returns 0 for the second client connection. That is, \"recv(self->fd, buf, size, MSG_DONTWAIT)\" always returns -1, and errno = EAGAIN. Causes the CotpConnection_readToTpktBuffer() function to return TPKT_WAITING all the time, system deadlock.\r\nThis is not the case with the previous version of 0.7.6. A comparison of socket_linux.c shows that version 0.7.6 USES \"read(self->fd, buf, size)\" here.\r\nSo, when I change the recv to read, I can connect multiple clients. In addition, I tried to change this to block mode \"recv(self->fd, buf, size, MSG_WAITALL)\", which also solves this problem.\r\n\r\nThe first time I mentioned a bug on github, if there is anything wrong, please give me more advice. ^_^\r\n"}}
{"actor":{"display_login":"xuwei2015"}}