{"id":1314,"date":"2013-08-08T10:18:13","date_gmt":"2013-08-08T16:18:13","guid":{"rendered":"http:\/\/www.philhassey.com\/blog\/?p=1314"},"modified":"2013-08-08T10:25:03","modified_gmt":"2013-08-08T16:25:03","slug":"getting-enet-to-work-with-marmalade","status":"publish","type":"post","link":"https:\/\/www.philhassey.com\/blog\/2013\/08\/08\/getting-enet-to-work-with-marmalade\/","title":{"rendered":"Getting ENet to work with Marmalade"},"content":{"rendered":"<p>Through a bit of Googling and whatnot, I got in touch with Joe Delgado who was able to provide a patch to fix ENet to work with Marmalade.  These are modifications to unix.c.  When I am making a Marmalade build of my games, I always have PLATFORM_MARMALADE defined.  So you can replace that with whatever you do.<\/p>\n<p>After the #ifdef __APPLE__ segment, add this to set up the correct defines, etc.<\/p>\n<pre name=\"xcode\" class=\"c\">\r\n#ifdef PLATFORM_MARMALADE\r\n#define SOMAXCONN 128\r\n#undef HAS_POLL\r\n#undef HAS_MSGHDR_FLAGS\r\n#undef HAS_FCNTL\r\n#include &lt;sys\/select.h>\r\n#include &lt;sys\/uio.h>\r\n#define HAS_SOCKLEN_T\r\n#endif\r\n<\/pre>\n<p>In enet_socket_send, it turns out the Marmalade sendmsg is broken.  So I replace:<\/p>\n<pre name=\"xcode\" class=\"c\">\r\n    msgHdr.msg_iov = (struct iovec *) buffers;\r\n    msgHdr.msg_iovlen = bufferCount;\r\n    sentLength = sendmsg (socket, & msgHdr, MSG_NOSIGNAL);\r\n<\/pre>\n<p>With<\/p>\n<pre name=\"xcode\" class=\"c\">\r\n#ifdef PLATFORM_MARMALADE\r\n    \/\/ concatenates buffers together\r\n\r\n    ENetBuffer * newBuffers;\r\n    char* d;\r\n    int i, totalSize;\r\n\r\n    newBuffers = (ENetBuffer*)malloc(sizeof(ENetBuffer));\r\n    totalSize = 0;\r\n    for (i=0;i&lt;bufferCount;i++) {\r\n        totalSize += (buffers+i)->dataLength;\r\n    }\r\n\r\n    newBuffers->data = malloc(totalSize);\r\n    newBuffers->dataLength = totalSize;\r\n    d = (char*)newBuffers->data;\r\n    for (i=0;i&lt;bufferCount;i++) {\r\n        memcpy(d, (buffers+i)->data, (buffers+i)->dataLength);\r\n        d += (buffers+i)->dataLength;\r\n    }\r\n\r\n    msgHdr.msg_iov = (struct iovec *) newBuffers;\r\n    msgHdr.msg_iovlen = totalSize;\r\n\r\n    sentLength = sendmsg (socket, & msgHdr, MSG_NOSIGNAL);\r\n\r\n    free(newBuffers->data);\r\n    free(newBuffers);\r\n\r\n#else\r\n\r\n    msgHdr.msg_iov = (struct iovec *) buffers;\r\n    msgHdr.msg_iovlen = bufferCount;\r\n    sentLength = sendmsg (socket, & msgHdr, MSG_NOSIGNAL);\r\n\r\n#endif\r\n<\/pre>\n<p>And that seems to get ENet working 100% with Marmalade.  I applied this patch to ENet 1.3.6 &#8230; The original patch was written for ENet 1.3.3, and I suspect it would work for the latest version of ENet.  I built this with Marmalade 6.3.2.  I&#8217;ve passed on a request to the Marmalade team to fix sendmsg so that the larger chunk of the code would no longer be necessary. <\/p>\n<p>-Phil<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Through a bit of Googling and whatnot, I got in touch with Joe Delgado who was able to provide a patch to fix ENet to work with Marmalade. These are modifications to unix.c. When I am making a Marmalade build of my games, I always have PLATFORM_MARMALADE defined. So you can replace that with whatever [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[112,24,13,6,121],"tags":[],"class_list":["post-1314","post","type-post","status-publish","format-standard","hentry","category-android","category-c","category-crazy","category-development","category-galcon2"],"_links":{"self":[{"href":"https:\/\/www.philhassey.com\/blog\/wp-json\/wp\/v2\/posts\/1314","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.philhassey.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.philhassey.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.philhassey.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.philhassey.com\/blog\/wp-json\/wp\/v2\/comments?post=1314"}],"version-history":[{"count":7,"href":"https:\/\/www.philhassey.com\/blog\/wp-json\/wp\/v2\/posts\/1314\/revisions"}],"predecessor-version":[{"id":1320,"href":"https:\/\/www.philhassey.com\/blog\/wp-json\/wp\/v2\/posts\/1314\/revisions\/1320"}],"wp:attachment":[{"href":"https:\/\/www.philhassey.com\/blog\/wp-json\/wp\/v2\/media?parent=1314"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.philhassey.com\/blog\/wp-json\/wp\/v2\/categories?post=1314"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.philhassey.com\/blog\/wp-json\/wp\/v2\/tags?post=1314"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}