1
0
mirror of https://github.com/haiwen/libsearpc.git synced 2025-09-01 04:47:16 +00:00

[conf,demo] add win32 support in demo

This commit is contained in:
lins05_win
2011-12-01 18:42:17 +08:00
committed by lins05
parent e0dbd4c248
commit 883ae12eb4
7 changed files with 349 additions and 19 deletions

View File

@@ -3,17 +3,24 @@
#include <string.h>
#include <errno.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <sys/stat.h>
#include <netinet/in.h>
#include <arpa/inet.h>
#include <glib-object.h>
#include "searpc-client.h"
#include "searpc-demo-packet.h"
#ifdef WIN32
#include <inttypes.h>
#include <winsock2.h>
typedef int socklen_t;
#else
#include <sys/types.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <arpa/inet.h>
#endif
#define BUFLEN 256
#define MAGIC_STRING "ABCD"
@@ -95,6 +102,11 @@ main(int argc, char *argv[])
g_type_init();
#ifdef WIN32
WSADATA wsadata;
WSAStartup(0x0101, &wsadata);
#endif
ret = sockfd = socket(AF_INET, SOCK_STREAM, 0);
if (ret < 0) {
fprintf(stderr, "socket failed: %s\n", strerror(errno));
@@ -102,7 +114,7 @@ main(int argc, char *argv[])
}
int on = 1;
if (setsockopt (sockfd, SOL_SOCKET, SO_REUSEADDR, &on, sizeof(on)) < 0) {
if (setsockopt (sockfd, SOL_SOCKET, SO_REUSEADDR, (char*)&on, sizeof(on)) < 0) {
fprintf (stderr, "setsockopt of SO_REUSEADDR error: %s\n", strerror(errno));
exit(-1);
}