{"action":"created","issue":{"url":"https://api.github.com/repos/ARMmbed/mbed-os/issues/3374","repository_url":"https://api.github.com/repos/ARMmbed/mbed-os","labels_url":"https://api.github.com/repos/ARMmbed/mbed-os/issues/3374/labels{/name}","comments_url":"https://api.github.com/repos/ARMmbed/mbed-os/issues/3374/comments","events_url":"https://api.github.com/repos/ARMmbed/mbed-os/issues/3374/events","html_url":"https://github.com/ARMmbed/mbed-os/pull/3374","id":193755934,"number":3374,"title":"Don't send events on close()","user":{"login":"bogdanm","id":211717,"avatar_url":"https://avatars.githubusercontent.com/u/211717?v=3","gravatar_id":"","url":"https://api.github.com/users/bogdanm","html_url":"https://github.com/bogdanm","followers_url":"https://api.github.com/users/bogdanm/followers","following_url":"https://api.github.com/users/bogdanm/following{/other_user}","gists_url":"https://api.github.com/users/bogdanm/gists{/gist_id}","starred_url":"https://api.github.com/users/bogdanm/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/bogdanm/subscriptions","organizations_url":"https://api.github.com/users/bogdanm/orgs","repos_url":"https://api.github.com/users/bogdanm/repos","events_url":"https://api.github.com/users/bogdanm/events{/privacy}","received_events_url":"https://api.github.com/users/bogdanm/received_events","type":"User","site_admin":false},"labels":[{"id":390046351,"url":"https://api.github.com/repos/ARMmbed/mbed-os/labels/needs:%20CI","name":"needs: CI","color":"fbca04","default":false}],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":16,"created_at":"2016-12-06T12:06:36Z","updated_at":"2016-12-07T15:57:57Z","closed_at":null,"pull_request":{"url":"https://api.github.com/repos/ARMmbed/mbed-os/pulls/3374","html_url":"https://github.com/ARMmbed/mbed-os/pull/3374","diff_url":"https://github.com/ARMmbed/mbed-os/pull/3374.diff","patch_url":"https://github.com/ARMmbed/mbed-os/pull/3374.patch"},"body":"Don't send events on close()\r\nIt's currently possible to generate a socket event when a non-blocking socket is closed:\r\n\r\n1. _pending is set to 0 in https://github.com/ARMmbed/mbed-os/blob/master/features/netsocket/TCPSocket.cpp#L22\r\n   when the socket is created.\r\n2. close() calls event() in https://github.com/ARMmbed/mbed-os/blob/master/features/netsocket/Socket.cpp#L66\r\n3. event() increments _pending, and since _pending is 1 it will call _callback() in https://github.com/ARMmbed/mbed-os/blob/master/features/netsocket/TCPSocket.cpp#L167\r\n\r\nHowever, if send() (for example) is called, this can happen:\r\n\r\n- send() is called and sets _pending to 0.\r\n- when the data is sent, event() is called, which sets _pending to 1 and calls _callback().\r\n- if close() is called at this point, there won't be an event generated for close() anymore,\r\n  since _pending will be set to 2.\r\n\r\n(same thing for recv)\r\n\r\nThis PR changes the initial value of _pending to 1 instead of 0, so that\r\nevents are never generated for close()."},"comment":{"url":"https://api.github.com/repos/ARMmbed/mbed-os/issues/comments/265486327","html_url":"https://github.com/ARMmbed/mbed-os/pull/3374#issuecomment-265486327","issue_url":"https://api.github.com/repos/ARMmbed/mbed-os/issues/3374","id":265486327,"user":{"login":"geky","id":1075160,"avatar_url":"https://avatars.githubusercontent.com/u/1075160?v=3","gravatar_id":"","url":"https://api.github.com/users/geky","html_url":"https://github.com/geky","followers_url":"https://api.github.com/users/geky/followers","following_url":"https://api.github.com/users/geky/following{/other_user}","gists_url":"https://api.github.com/users/geky/gists{/gist_id}","starred_url":"https://api.github.com/users/geky/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/geky/subscriptions","organizations_url":"https://api.github.com/users/geky/orgs","repos_url":"https://api.github.com/users/geky/repos","events_url":"https://api.github.com/users/geky/events{/privacy}","received_events_url":"https://api.github.com/users/geky/received_events","type":"User","site_admin":false},"created_at":"2016-12-07T15:57:57Z","updated_at":"2016-12-07T15:57:57Z","body":"/morph test-nightly"}}
{"actor":{"display_login":"geky"}}