Skip to content

mingw32 #124

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
*.la
.deps
.libs
*.exe
src/ios_webkit_debug_proxy
examples/dl_client
examples/wi_client
Expand Down
31 changes: 28 additions & 3 deletions configure.ac
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,34 @@ AC_TYPE_UINT64_T
AC_TYPE_UINT8_T

# Checks for library functions.
AC_FUNC_MALLOC
AC_FUNC_REALLOC
AC_CHECK_FUNCS([memmove memset regcomp select socket stpcpy strcasecmp strncasecmp strchr strdup strndup strrchr strstr strtol])
AC_CHECK_FUNCS([malloc realloc memmove memset regcomp select socket stpcpy strcasecmp strncasecmp strchr strdup strndup strrchr strstr strtol strcasestr va_copy vasprintf asprintf stpncpy stpcpy strndup getline htobe64])

# Check for pcre presence if regex.h is absent
AC_CHECK_HEADER(regex.h, [ac_have_regex_h="yes"], [ac_have_regex_h="no"])
if test "x$ac_have_regex_h" = "xno"; then
PKG_CHECK_MODULES(libpcreposix, libpcreposix, [], [AC_MSG_ERROR([Neither regex.h nor pcre headers were found])])
else
AC_DEFINE(HAVE_REGEX_H, 1, [regex.h is present])
fi

# Check for operating system
AC_MSG_CHECKING([whether to enable WIN32 build settings])
case ${host_os} in
*mingw32*|*msys*|*cygwin*)
win32=true
AC_MSG_RESULT([yes])
AC_DEFINE(WIN32_LEAN_AND_MEAN, 1, [Define to limit the scope of windows.h])
AC_DEFINE(__USE_MINGW_ANSI_STDIO, 1, [Define to use C99 printf/snprintf in MinGW])
;;
*)
win32=false
AC_MSG_RESULT([no])
;;
esac
AM_CONDITIONAL(WIN32, test x$win32 = xtrue)

# Check endianess
AC_C_BIGENDIAN

AC_CONFIG_FILES([Makefile src/Makefile include/Makefile examples/Makefile])

Expand Down
14 changes: 13 additions & 1 deletion examples/dl_client.c
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,23 @@
//
// An example device_listener client
//
#ifdef HAVE_CONFIG_H
#include <config.h>
#endif

#include <errno.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#ifdef WIN32
#include <windows.h>
#include <winsock2.h>
#else
#include <sys/socket.h>
#endif
#include <unistd.h>

#include "device_listener.h"
#include <iwdp/device_listener.h>

struct my_struct {
int fd;
Expand Down Expand Up @@ -66,7 +74,11 @@ int main(int argc, char** argv) {
break;
}
}
#ifndef WIN32
close(fd);
#else
closesocket(fd);
#endif
free(dl->state);
dl_free(dl);
return 0;
Expand Down
18 changes: 17 additions & 1 deletion examples/wi_client.c
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,25 @@
//
// A minimal webinspector client
//
#ifdef HAVE_CONFIG_H
#include <config.h>
#endif

#include <errno.h>
#include <signal.h>
#include <stdbool.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#ifdef WIN32
#include <windows.h>
#include <winsock2.h>
#else
#include <sys/socket.h>
#endif
#include <unistd.h>

#include "webinspector.h"
#include <iwdp/webinspector.h>

// our state
struct my_wi_struct {
Expand Down Expand Up @@ -121,7 +129,11 @@ int main(int argc, char **argv) {
size_t buf_length = 1024;
while (!quit_flag) {
ssize_t read_bytes = recv(fd, buf, buf_length, 0);
#ifndef WIN32
if (read_bytes < 0 && errno == EWOULDBLOCK) {
#else
if (read_bytes && WSAGetLastError() != WSAEWOULDBLOCK) {
#endif
continue;
}
if (wi->on_recv(wi, buf, read_bytes)) {
Expand All @@ -135,7 +147,11 @@ int main(int argc, char **argv) {
memset(my_wi, 0, sizeof(struct my_wi_struct));
free(my_wi);
if (fd >= 0) {
#ifndef WIN32
close(fd);
#else
closesocket(fd);
#endif
}
return 0;
}
29 changes: 28 additions & 1 deletion examples/ws_echo1.c
Original file line number Diff line number Diff line change
Expand Up @@ -4,24 +4,39 @@
//
// A minimal websocket "echo" server
//
#ifdef HAVE_CONFIG_H
#include <config.h>
#endif

#include <stdio.h>
#include <stdlib.h>
#include <string.h>

#include "ws_echo_common.h"
#include "websocket.h"
#include <iwdp/websocket.h>

#ifdef WIN32
#include <windows.h>
#include <winsock2.h>
#else
#include <sys/ioctl.h>
#include <sys/socket.h>
#include <arpa/inet.h>
#endif
#include <errno.h>
#include <unistd.h>

#define BUF_LEN 1024
#define PORT 8080

int main(int argc, char** argv) {
#ifdef WIN32
WSADATA wsa_data;
if (WSAStartup(MAKEWORD(2,2), &wsa_data) != ERROR_SUCCESS) {
fprintf(stderr, "WSAStartup failed!\n");
ExitProcess(-1);
}
#endif
int port = PORT;

int sfd = socket(AF_INET, SOCK_STREAM, 0);
Expand All @@ -38,7 +53,11 @@ int main(int argc, char** argv) {
bind(sfd, (struct sockaddr*)&local, sizeof(local)) < 0 ||
listen(sfd, 1)) {
perror("Unable to bind");
#ifndef WIN32
close(sfd);
#else
closesocket(sfd);
#endif
return -1;
}

Expand All @@ -65,10 +84,18 @@ int main(int argc, char** argv) {
break;
}
}
#ifndef WIN32
close(fd);
#else
closesocket(fd);
#endif
my_free(my);
}

#ifndef WIN32
close(sfd);
#else
closesocket(sfd);
#endif
return ret;
}
10 changes: 9 additions & 1 deletion examples/ws_echo2.c
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@
//
// A select-based websocket "echo" server
//
#ifdef HAVE_CONFIG_H
#include <config.h>
#endif

#include <signal.h>
#include <stdbool.h>
Expand All @@ -12,11 +15,16 @@
#include <string.h>
#include <assert.h>

#ifdef WIN32
#include <windows.h>
#include <winsock2.h>
#else
#include <sys/socket.h>
#include <arpa/inet.h>
#endif
#include <errno.h>

#include "socket_manager.h"
#include <iwdp/socket_manager.h>
#include "ws_echo_common.h"

struct my_sm_struct {
Expand Down
12 changes: 10 additions & 2 deletions examples/ws_echo_common.c
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,25 @@
//
// A minimal websocket "echo" server
//
#ifdef HAVE_CONFIG_H
#include <config.h>
#endif

#define _GNU_SOURCE
#include <stdbool.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#ifdef WIN32
#include <windows.h>
#include <winsock2.h>
#else
#include <sys/socket.h>
#endif

#include "ws_echo_common.h"
#include "websocket.h"

#include <iwdp/websocket.h>
#include "asprintf.h"

// websocket callbacks:

Expand Down
2 changes: 1 addition & 1 deletion examples/ws_echo_common.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ extern "C" {
#include <stdint.h>
#include <stdlib.h>

#include "websocket.h"
#include <iwdp/websocket.h>

struct my_struct {
int fd;
Expand Down
26 changes: 14 additions & 12 deletions include/Makefile.am
Original file line number Diff line number Diff line change
@@ -1,16 +1,18 @@
# Google BSD license http://code.google.com/google_bsd_license.html
# Copyright 2012 Google Inc. [email protected]

EXTRA_DIST = asprintf.h getline.h stpcpy.h stpncpy.h strcasestr.h strndup.h

nobase_include_HEADERS = \
base64.h \
char_buffer.h \
device_listener.h \
hash_table.h \
ios_webkit_debug_proxy.h \
port_config.h \
rpc.h \
sha1.h \
socket_manager.h \
validate_utf8.h \
webinspector.h \
websocket.h
iwdp/base64.h \
iwdp/char_buffer.h \
iwdp/device_listener.h \
iwdp/hash_table.h \
iwdp/ios_webkit_debug_proxy.h \
iwdp/port_config.h \
iwdp/rpc.h \
iwdp/sha1.h \
iwdp/socket_manager.h \
iwdp/validate_utf8.h \
iwdp/webinspector.h \
iwdp/websocket.h
Loading