/2013/08/14/How-to-compile-Mongoose-HTTP-server-on-mingw/

{"item":{"status":"visible","url":"\/2013\/08\/14\/How-to-compile-Mongoose-HTTP-server-on-mingw\/","trash":"","name":"How-to-compile-Mongoose-HTTP-server-on-mingw","parent":"","title":"How to compile Mongoose HTTP server on mingw","date":"2013-08-14 03:17:48","filepath":"posts\/20130814_How-to-compile-Mongoose-HTTP-server-on-mingw.xml.json","type":"post","content":"<p><img style=\"float: left; margin: 10px;\" src=\"http:\/\/www.8bitrobot.com\/media\/uploads\/2012\/01\/gear.png\" alt=\"\" width=\"60\" height=\"64\" \/>The open source project <a href=\"https:\/\/github.com\/valenok\/mongoose\" target=\"_blank\">Mongoose<\/a> is a tiny HTTP server written in C. &nbsp;I wanted to try it out using a free compiler on my Windows box, g++ on mingw, and had to resort to this hack to get it compiled:<\/p>\n<ol>\n<li>Use git to clone the project from github<\/li>\n<li>Copy the example <span style=\"font-family: 'courier new', courier;\">hello.c<\/span> in examples to the parent directory<\/li>\n<li>Apply the patch below to <span style=\"font-family: 'courier new', courier;\">mongoose.c<\/span><\/li>\n<li>Then build: &nbsp;<span style=\"font-family: 'courier new', courier;\">g++ mongoose.c hello.c -lpthread -lwsock32<\/span><\/li>\n<\/ol>\n<p>The patch (apply with <span style=\"font-family: 'courier new', courier;\">patch -p0 &lt; file.patch<\/span>):<\/p>\n<pre>diff --git mongoose.c mongoose.c\nindex 47cd9be..c324136 100644\n--- mongoose.c\n+++ mongoose.c\n@@ -108,8 +108,10 @@ typedef long off_t;\n #define strtoll(x, y, z) _atoi64(x)\n #else\n #define __func__ __FUNCTION__\n-#define strtoull(x, y, z) _strtoui64(x, y, z)\n-#define strtoll(x, y, z) _strtoi64(x, y, z)\n+\/\/#define strtoull(x, y, z) _strtoui64(x, y, z)\n+\/\/#define strtoll(x, y, z) _strtoi64(x, y, z)\n+#define strtoull(x, y, z) (unsigned __int64) _atoi64(x)\n+#define strtoll(x, y, z) _atoi64(x)\n #endif \/\/ _MSC_VER\n \n #define ERRNO GetLastError()\n@@ -1630,7 +1632,7 @@ static int alloc_vprintf2(char **buf, const char *fmt, va_list ap) {\n *buf = NULL;\n while (len == -1) {\n if (*buf) free(*buf);\n- *buf = malloc(size *= 4);\n+ *buf = (char*)malloc(size *= 4);\n if (!*buf) break;\n va_copy(ap_copy, ap);\n len = vsnprintf(*buf, size, fmt, ap_copy);\n@@ -4596,7 +4598,7 @@ static int set_ports_option(struct mg_context *ctx) {\n \/\/ On Windows, SO_REUSEADDR is recommended only for\n \/\/ broadcast UDP sockets\n setsockopt(so.sock, SOL_SOCKET, SO_REUSEADDR,\n- (void *) &amp;on, sizeof(on)) != 0 ||\n+ (char *) (&amp;on), sizeof(on)) != 0 ||\n #if defined(USE_IPV6)\n (so.lsa.sa.sa_family == AF_INET6 &amp;&amp;\n setsockopt(so.sock, IPPROTO_IPV6, IPV6_V6ONLY, (void *) &amp;off,\n@@ -5209,8 +5211,8 @@ static int set_sock_timeout(SOCKET sock, int milliseconds) {\n t.tv_sec = milliseconds \/ 1000;\n t.tv_usec = (milliseconds * 1000) % 1000000;\n #endif\n- return setsockopt(sock, SOL_SOCKET, SO_RCVTIMEO, (void *) &amp;t, sizeof(t)) ||\n- setsockopt(sock, SOL_SOCKET, SO_SNDTIMEO, (void *) &amp;t, sizeof(t));\n+ return setsockopt(sock, SOL_SOCKET, SO_RCVTIMEO, (char *) &amp;t, sizeof(t)) ||\n+ setsockopt(sock, SOL_SOCKET, SO_SNDTIMEO, (char *) &amp;t, sizeof(t));\n }\n \n static void accept_new_connection(const struct socket *listener,\n@@ -5238,7 +5240,7 @@ static void accept_new_connection(const struct socket *listener,\n \/\/ keep-alive, next keep-alive handshake will figure out that the client\n \/\/ is down and will close the server end.\n \/\/ Thanks to Igor Klopov who suggested the patch.\n- setsockopt(so.sock, SOL_SOCKET, SO_KEEPALIVE, (void *) &amp;on, sizeof(on));\n+ setsockopt(so.sock, SOL_SOCKET, SO_KEEPALIVE, (char *) &amp;on, sizeof(on));\n set_sock_timeout(so.sock, atoi(ctx-&gt;config[REQUEST_TIMEOUT]));\n produce_socket(ctx, &amp;so);\n }\n<\/pre>"}}
comments powered by Disqus
 

Lorem Ipsum

Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat.

Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.

Lorem

Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat.

 
This page is best viewed with Firefox 3.5+, Chrome 5+, Safari 5+, Opera 10.6+, IE 9+
Copyright © 2014 8bitrobot.com