Permalink
Browse files

add libpomelo windows build support

  • Loading branch information...
1 parent 1b041d6 commit 1bf0eef267becbba6bd49127c28f42893955cb37 @fantasyni fantasyni committed Mar 25, 2013
View
@@ -4,7 +4,7 @@
'target_name': 'jansson',
'type': '<(library)',
'include_dirs': [
- './src',
+ './src'
],
'sources': [
'src/dump.c',
@@ -21,12 +21,32 @@
'src/utf.c',
'src/utf.h',
'src/value.c',
+ 'src/jansson.h',
+ 'src/jansson_config.h'
+ ],
+ 'conditions': [
+ ['OS == "win"', {
+ 'defines': [
+ 'WIN32',
+ '_CRT_NONSTDC_NO_DEPRECATE',
+ '_DEBUG',
+ '_WINDOWS',
+ '_USRDLL',
+ 'JANSSON_DLL_EXPORTS',
+ '_WINDLL',
+ '_UNICODE',
+ 'UNICODE'
+ ]
+ }],
+ ['OS != "win"',{
+ 'ldflags': [
+ '-no-undefined',
+ '-export-symbols-regex \'^json_\'',
+ '-version-info 8:0:4',
+ ]
+ }
+ ]
],
- 'ldflags': [
- '-no-undefined',
- '-export-symbols-regex \'^json_\'',
- '-version-info 8:0:4',
- ]
},
],
}
@@ -24,7 +24,11 @@
#ifdef __cplusplus
#define JSON_INLINE inline
#else
-#define JSON_INLINE inline
+ #ifdef WIN32
+ #define JSON_INLINE __inline
+ #else
+ #define JSON_INLINE inline
+ #endif
#endif
/* If your compiler supports the `long long` type and the strtoll()
View
@@ -1,4 +1,8 @@
+#ifdef _WIN32
+#include <winsock2.h>
+#else
#include <unistd.h>
+#endif
#include <string.h>
#include <stdlib.h>
#include "pomelo.h"
@@ -68,7 +72,11 @@ int main() {
// main thread sleep 3 second and then destroy the client instance.
printf("Main thread sleep 3 second and then destroy the client instance.\n");
- sleep(3);
+#ifdef _WIN32
+Sleep(3000);
+#else
+sleep(3);
+#endif
// release the client
pc_client_destroy(client);
View
@@ -1,4 +1,8 @@
+#ifdef _WIN32
+#include <winsock2.h>
+#else
#include <unistd.h>
+#endif
#include <string.h>
#include <stdlib.h>
#include "pomelo.h"
View
@@ -1,4 +1,8 @@
+#ifdef _WIN32
+#include <winsock2.h>
+#else
#include <unistd.h>
+#endif
#include <string.h>
#include <stdlib.h>
#include "pomelo.h"
@@ -1,3 +1,8 @@
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+
#ifndef PC_MAP_H
#define PC_MAP_H
@@ -119,3 +124,7 @@ void *pc_map_del(pc_map_t *map, const char *key);
void pc_map_clear(pc_map_t *map);
#endif /* PC_MAP_H */
+
+#ifdef __cplusplus
+}
+#endif
@@ -8,19 +8,18 @@
#include <stdint.h>
#include <stddef.h>
-#include <stdbool.h>
#include "jansson.h"
/*
* protobuf encode
*/
-bool pc_pb_encode(uint8_t *buf, size_t len, size_t *written,
+int pc_pb_encode(uint8_t *buf, size_t len, size_t *written,
json_t *protos, json_t *msg);
/*
* protobuf decode
*/
-bool pc_pb_decode(uint8_t *buf, size_t len, json_t *protos,
+int pc_pb_decode(uint8_t *buf, size_t len, json_t *protos,
json_t *result);
#endif
View
@@ -22,6 +22,12 @@ extern "C" {
# define PC_EXTERN /* nothing */
#endif
+#ifdef _WIN32
+ #include <winsock2.h>
+#else
+ #include <netinet/in.h>
+#endif
+
#include "uv.h"
#include "jansson.h"
#include "pomelo-private/map.h"
@@ -41,7 +47,7 @@ typedef struct pc_request_s pc_request_t;
typedef struct pc_notify_s pc_notify_t;
typedef struct pc_msg_s pc_msg_t;
typedef struct pc_pkg_parser_s pc_pkg_parser_t;
-typedef struct pc_buf_s pc_buf_t;
+typedef struct uv_buf_t pc_buf_t;
/**
* State machine for Pomelo package parser
@@ -188,10 +194,10 @@ typedef void (*pc_msg_encode_done_cb)(pc_client_t *client, pc_buf_t buf);
* Simple structure for memory block.
* The pc_buf_s is cheap and could be passed by value.
*/
-struct pc_buf_s {
+/*struct pc_buf_s {
char *base;
size_t len;
-};
+};*/
/**
* Transport structure.
View
@@ -42,6 +42,45 @@
'src/protocol.c',
'src/thread.c',
],
+ 'conditions': [
+ ['OS == "win"', {
+ 'msvs_settings': {
+ 'VCCLCompilerTool': {
+ 'AdditionalOptions': [ '/TP' ],
+ }
+ },
+ 'defines': [
+ '_WIN32',
+ 'WIN32',
+ '_CRT_NONSTDC_NO_DEPRECATE',
+ '_DEBUG',
+ '_WINDOWS',
+ '_USRDLL',
+ 'JANSSON_DLL_EXPORTS',
+ '_WINDLL',
+ '_UNICODE',
+ 'UNICODE'
+ ],
+ 'link_settings': {
+ 'libraries': [
+ '-ladvapi32.lib',
+ '-liphlpapi.lib',
+ '-lpsapi.lib',
+ '-lshell32.lib',
+ '-lws2_32.lib'
+ ],
+ },
+ }
+ ],
+ ['OS != "win"',{
+ 'ldflags': [
+ '-no-undefined',
+ '-export-symbols-regex \'^json_\'',
+ '-version-info 8:0:4',
+ ]
+ }
+ ]
+ ],
},
{
'target_name': 'destroy',
@@ -56,7 +95,37 @@
],
'sources': [
'example/destroy.c'
- ]
+ ],
+ 'conditions' : [
+ ['OS == "win"', {
+ 'msvs_settings': {
+ 'VCCLCompilerTool': {
+ 'AdditionalOptions': [ '/TP' ],
+ }
+ },
+ 'defines': [
+ 'WIN32',
+ '_CRT_NONSTDC_NO_DEPRECATE',
+ '_DEBUG',
+ '_WINDOWS',
+ '_USRDLL',
+ 'JANSSON_DLL_EXPORTS',
+ '_WINDLL',
+ '_UNICODE',
+ 'UNICODE'
+ ],
+ 'link_settings': {
+ 'libraries': [
+ '-ladvapi32.lib',
+ '-liphlpapi.lib',
+ '-lpsapi.lib',
+ '-lshell32.lib',
+ '-lws2_32.lib'
+ ],
+ },
+ }
+ ]
+ ],
},
{
'target_name': 'notify',
@@ -71,6 +140,36 @@
],
'sources': [
'example/notify.c'
+ ],
+ 'conditions':[
+ ['OS == "win"', {
+ 'msvs_settings': {
+ 'VCCLCompilerTool': {
+ 'AdditionalOptions': [ '/TP' ],
+ }
+ },
+ 'defines': [
+ 'WIN32',
+ '_CRT_NONSTDC_NO_DEPRECATE',
+ '_DEBUG',
+ '_WINDOWS',
+ '_USRDLL',
+ 'JANSSON_DLL_EXPORTS',
+ '_WINDLL',
+ '_UNICODE',
+ 'UNICODE'
+ ],
+ 'link_settings': {
+ 'libraries': [
+ '-ladvapi32.lib',
+ '-liphlpapi.lib',
+ '-lpsapi.lib',
+ '-lshell32.lib',
+ '-lws2_32.lib'
+ ],
+ },
+ }
+ ],
]
},
{
@@ -86,6 +185,36 @@
],
'sources': [
'example/request.c'
+ ],
+ 'conditions': [
+ ['OS == "win"', {
+ 'msvs_settings': {
+ 'VCCLCompilerTool': {
+ 'AdditionalOptions': [ '/TP' ],
+ }
+ },
+ 'defines': [
+ 'WIN32',
+ '_CRT_NONSTDC_NO_DEPRECATE',
+ '_DEBUG',
+ '_WINDOWS',
+ '_USRDLL',
+ 'JANSSON_DLL_EXPORTS',
+ '_WINDLL',
+ '_UNICODE',
+ 'UNICODE'
+ ],
+ 'link_settings': {
+ 'libraries': [
+ '-ladvapi32.lib',
+ '-liphlpapi.lib',
+ '-lpsapi.lib',
+ '-lshell32.lib',
+ '-lws2_32.lib'
+ ],
+ },
+ }
+ ],
]
}
],
View
@@ -2,7 +2,7 @@
#include <stdio.h>
#include <stddef.h>
#include <string.h>
-#include <unistd.h>
+//#include <unistd.h>
#include "pomelo.h"
#include "pomelo-private/listener.h"
#include "pomelo-protocol/package.h"
@@ -196,7 +196,11 @@ void pc_client_destroy(pc_client_t *client) {
if(PC_ST_CLOSED != client->state) {
pc_client_stop(client);
// wait uv_loop_t stop
- sleep(1);
+#ifdef _WIN32
+ Sleep(1000);
+#else
+ sleep(1);
+#endif
pc__client_clear(client);
}
@@ -265,7 +269,7 @@ int pc_add_listener(pc_client_t *client, const char *event,
listener->cb = event_cb;
uv_mutex_lock(&client->listener_mutex);
- ngx_queue_t *head = pc_map_get(client->listeners, event);
+ ngx_queue_t *head = (ngx_queue_t *)pc_map_get(client->listeners, event);
if(head == NULL) {
head = (ngx_queue_t *)malloc(sizeof(ngx_queue_t));
View
@@ -80,7 +80,7 @@ int pc_map_set(pc_map_t *map, const char *key, void *value) {
memset(pair, 0, sizeof(pc__pair_t));
ngx_queue_init(&pair->queue);
- cpy_key = malloc(key_len);
+ cpy_key = (char *)malloc(key_len);
if(cpy_key == NULL) {
goto error;
}
Oops, something went wrong.

0 comments on commit 1bf0eef

Please sign in to comment.