{"id":871,"date":"2011-08-09T21:28:16","date_gmt":"2011-08-10T04:28:16","guid":{"rendered":"http:\/\/www.graphics-muse.org\/wp\/?p=871"},"modified":"2011-08-09T21:28:16","modified_gmt":"2011-08-10T04:28:16","slug":"writev-vs-send-when-using-signals","status":"publish","type":"post","link":"https:\/\/www.graphics-muse.org\/wp\/?p=871","title":{"rendered":"writev() vs send() when using signals"},"content":{"rendered":"<p>I ran into an interesting problem today.&nbsp; I have a C application with functions calling <span style=\"font-family: courier new,courier,monospace;\">writev<\/span>() to send data across the network.&nbsp; The messages being sent range from very small &#8211; a few bytes &#8211; to over 1MB.&nbsp; These functions have worked great up to this point.<\/p>\n<p>Today I integrated a number of high resolution timers.&nbsp; When the timers go off they raise a signal which is handled by a signal handler.&nbsp; It turns out that writev() can be interrupted by these signals.&nbsp; Unfortunately, it doesn&#39;t seem to recover correctly from that interruption.&nbsp; I haven&#39;t figured out why, but I did find out that <span style=\"font-family: courier new,courier,monospace;\">send<\/span>() does recover correctly.<\/p>\n<p>Since I don&#39;t need the feature provided by the iovec structure writev() uses there was no need to keep it.&nbsp; So I switched to using send() in these functions, along with wrapping the call inside a loop to guarantee the full message was sent.&nbsp; See, the signal causes the send() to return early, but it returns the number of bytes it actually wrote.&nbsp; So you can catch that it didn&#39;t send everything and just try resending whatever is left.&nbsp; <\/p>\n<p>This works great and is not affected by the frequent signals.&nbsp; This was interesting only because I didn&#39;t see anything in the man pages warning me about the problems with writev() and signals.&nbsp; But at least now I know what to do if I hit this problem again.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>I ran into an interesting problem today.&nbsp; I have a C application with functions calling writev() to send data across the network.&nbsp; The messages being sent range from very small &#8211; a few bytes &#8211; to over 1MB.&nbsp; These functions have worked great up to this point. Today I integrated a number of high resolution [&hellip;]<\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"ngg_post_thumbnail":0,"jetpack_post_was_ever_published":false,"footnotes":"","jetpack_publicize_message":"","jetpack_publicize_feature_enabled":true,"jetpack_social_post_already_shared":false,"jetpack_social_options":{"image_generator_settings":{"template":"highway","enabled":false},"version":2}},"categories":[5,6],"tags":[542,552,553],"class_list":{"0":"post-871","1":"post","2":"type-post","3":"status-publish","4":"format-standard","6":"category-linux","7":"category-software-development","8":"tag-signal","9":"tag-signals","10":"tag-writev","11":"czr-hentry"},"jetpack_publicize_connections":[],"aioseo_notices":[],"jetpack_featured_media_url":"","jetpack_shortlink":"https:\/\/wp.me\/pe9t8-e3","jetpack_sharing_enabled":true,"jetpack-related-posts":[],"jetpack_likes_enabled":true,"_links":{"self":[{"href":"https:\/\/www.graphics-muse.org\/wp\/index.php?rest_route=\/wp\/v2\/posts\/871","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.graphics-muse.org\/wp\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.graphics-muse.org\/wp\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.graphics-muse.org\/wp\/index.php?rest_route=\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/www.graphics-muse.org\/wp\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=871"}],"version-history":[{"count":1,"href":"https:\/\/www.graphics-muse.org\/wp\/index.php?rest_route=\/wp\/v2\/posts\/871\/revisions"}],"predecessor-version":[{"id":872,"href":"https:\/\/www.graphics-muse.org\/wp\/index.php?rest_route=\/wp\/v2\/posts\/871\/revisions\/872"}],"wp:attachment":[{"href":"https:\/\/www.graphics-muse.org\/wp\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=871"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.graphics-muse.org\/wp\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=871"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.graphics-muse.org\/wp\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=871"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}