Revision: 14539
Author: adrian.chadd
Date: Mon Apr 5 05:15:45 2010
Log: Issue #94 - migrate WIN32_pipe out into libiapp/ as it currently uses
some libiapp-specific stuff.
I'll tidy up more of it later.
http://code.google.com/p/lusca-cache/source/detail?r=14539
Added:
/branches/LUSCA_HEAD/libiapp/win32_pipe.c
/branches/LUSCA_HEAD/libiapp/win32_pipe.h
Modified:
/branches/LUSCA_HEAD/include/util.h
/branches/LUSCA_HEAD/lib/win32lib.c
/branches/LUSCA_HEAD/libiapp/Makefile.am
=======================================
--- /dev/null
+++ /branches/LUSCA_HEAD/libiapp/win32_pipe.c Mon Apr 5 05:15:45 2010
@@ -0,0 +1,143 @@
+
+/*
+ * $Id: win32lib.c 14534 2010-04-03 13:47:46Z adrian.chadd $
+ *
+ * Windows support
+ * AUTHOR: Guido Serassio <[email protected]>
+ * inspired by previous work by Romeo Anghelache & Eric Stern.
+ *
+ * SQUID Web Proxy Cache http://www.squid-cache.org/
+ * ----------------------------------------------------------
+ *
+ * Squid is the result of efforts by numerous individuals from
+ * the Internet community; see the CONTRIBUTORS file for full
+ * details. Many organizations have provided support for Squid's
+ * development; see the SPONSORS file for full details. Squid is
+ * Copyrighted (C) 2001 by the Regents of the University of
+ * California; see the COPYRIGHT file for full details. Squid
+ * incorporates software developed and/or copyrighted by other
+ * sources; see the CREDITS file for full details.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111, USA.
+ *
+ */
+#include "../include/config.h"
+
+/* The following code section is part of the native Windows Squid port */
+#if defined(_SQUID_MSWIN_)
+
+#undef strerror
+#define sys_nerr _sys_nerr
+
+#undef assert
+#include <assert.h>
+#include <stdio.h>
+#include <limits.h>
+#include <errno.h>
+#include <windows.h>
+#include <string.h>
+#include <sys/timeb.h>
+#if HAVE_WIN32_PSAPI
+#include <psapi.h>
+#endif
+
+THREADLOCAL int ws32_result;
+THREADLOCAL int _so_err;
+THREADLOCAL int _so_err_siz = sizeof(int);
+LPCRITICAL_SECTION dbg_mutex = NULL;
+
+/* internal to Microsoft CRTLIB */
+#define FPIPE 0x08 /* file handle refers to a pipe */
+typedef struct {
+ long osfhnd; /* underlying OS file HANDLE */
+ char osfile; /* attributes of file (e.g., open in text
mode?) */
+ char pipech; /* one char buffer for handles opened on pipes
*/
+#ifdef _MT
+ int lockinitflag;
+ CRITICAL_SECTION lock;
+#endif /* _MT */
+} ioinfo;
+
+#define IOINFO_L2E 5
+#define IOINFO_ARRAY_ELTS (1 << IOINFO_L2E)
+#define _pioinfo(i) ( __pioinfo[(i) >> IOINFO_L2E] + ((i) &
(IOINFO_ARRAY_ELTS - 1)) )
+#define _osfile(i) ( _pioinfo(i)->osfile )
+#define _osfhnd(i) ( _pioinfo(i)->osfhnd )
+
+#if defined(_MSC_VER) /* Microsoft C Compiler ONLY */
+
+extern _CRTIMP ioinfo *__pioinfo[];
+int __cdecl _free_osfhnd(int);
+#define FOPEN 0x01 /* file handle open */
+
+#elif defined(__MINGW32__) /* MinGW environment */
+
+#define FOPEN 0x01 /* file handle open */
+__MINGW_IMPORT ioinfo *__pioinfo[];
+int _free_osfhnd(int);
+
+#endif
+
+#if defined(_SQUID_MSWIN_)
+int
+WIN32_pipe(int handles[2])
+{
+ int new_socket;
+ fde *F = NULL;
+
+ struct sockaddr_in serv_addr;
+ int len = sizeof(serv_addr);
+ u_short handle1_port;
+
+ handles[0] = handles[1] = -1;
+
+ statCounter.syscalls.sock.sockets++;
+ if ((new_socket = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP)) < 0)
+ return -1;
+
+ memset((void *) &serv_addr, 0, sizeof(serv_addr));
+ serv_addr.sin_family = AF_INET;
+ serv_addr.sin_port = htons(0);
+ serv_addr.sin_addr = local_addr;
+
+ if (bind(new_socket, (SOCKADDR *) & serv_addr, len) < 0 ||
+ listen(new_socket, 1) < 0 || getsockname(new_socket, (SOCKADDR *) &
serv_addr, &len) < 0 ||
+ (handles[1] = socket(PF_INET, SOCK_STREAM, 0)) < 0) {
+ closesocket(new_socket);
+ return -1;
+ }
+ handle1_port = ntohs(serv_addr.sin_port);
+ if (connect(handles[1], (SOCKADDR *) & serv_addr, len) < 0 ||
+ (handles[0] = accept(new_socket, (SOCKADDR *) & serv_addr, &len)) < 0) {
+ closesocket(handles[1]);
+ handles[1] = -1;
+ closesocket(new_socket);
+ return -1;
+ }
+ closesocket(new_socket);
+
+ F = &fd_table[handles[0]];
+ F->local_addr = local_addr;
+ F->local_port = ntohs(serv_addr.sin_port);
+
+ F = &fd_table[handles[1]];
+ F->local_addr = local_addr;
+ xstrncpy(F->ipaddr, inet_ntoa(local_addr), 16);
+ F->remote_port = handle1_port;
+
+ return 0;
+}
+
+#endif /* _SQUID_MSWIN_ */
=======================================
--- /dev/null
+++ /branches/LUSCA_HEAD/libiapp/win32_pipe.h Mon Apr 5 05:15:45 2010
@@ -0,0 +1,6 @@
+#ifndef __WIN32_PIPE_H__
+#define __WIN32_PIPE_H__
+
+extern int WIN32_pipe(int handles[2]);
+
+#endif
=======================================
--- /branches/LUSCA_HEAD/include/util.h Sat Apr 3 06:47:46 2010
+++ /branches/LUSCA_HEAD/include/util.h Mon Apr 5 05:15:45 2010
@@ -163,7 +163,6 @@
extern const char *WIN32_strerror(int);
extern void WIN32_maperror(unsigned long);
extern int WIN32_Close_FD_Socket(int);
-extern int WIN32_pipe(int[2]);
extern int WIN32_getrusage(int, struct rusage *);
#endif
=======================================
--- /branches/LUSCA_HEAD/lib/win32lib.c Sat Apr 3 06:47:46 2010
+++ /branches/LUSCA_HEAD/lib/win32lib.c Mon Apr 5 05:15:45 2010
@@ -793,55 +793,6 @@
#if defined(_SQUID_MSWIN_)
-
-int
-WIN32_pipe(int handles[2])
-{
- int new_socket;
- fde *F = NULL;
-
- struct sockaddr_in serv_addr;
- int len = sizeof(serv_addr);
- u_short handle1_port;
-
- handles[0] = handles[1] = -1;
-
- statCounter.syscalls.sock.sockets++;
- if ((new_socket = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP)) < 0)
- return -1;
-
- memset((void *) &serv_addr, 0, sizeof(serv_addr));
- serv_addr.sin_family = AF_INET;
- serv_addr.sin_port = htons(0);
- serv_addr.sin_addr = local_addr;
-
- if (bind(new_socket, (SOCKADDR *) & serv_addr, len) < 0 ||
- listen(new_socket, 1) < 0 || getsockname(new_socket, (SOCKADDR *) &
serv_addr, &len) < 0 ||
- (handles[1] = socket(PF_INET, SOCK_STREAM, 0)) < 0) {
- closesocket(new_socket);
- return -1;
- }
- handle1_port = ntohs(serv_addr.sin_port);
- if (connect(handles[1], (SOCKADDR *) & serv_addr, len) < 0 ||
- (handles[0] = accept(new_socket, (SOCKADDR *) & serv_addr, &len)) < 0) {
- closesocket(handles[1]);
- handles[1] = -1;
- closesocket(new_socket);
- return -1;
- }
- closesocket(new_socket);
-
- F = &fd_table[handles[0]];
- F->local_addr = local_addr;
- F->local_port = ntohs(serv_addr.sin_port);
-
- F = &fd_table[handles[1]];
- F->local_addr = local_addr;
- xstrncpy(F->ipaddr, inet_ntoa(local_addr), 16);
- F->remote_port = handle1_port;
-
- return 0;
-}
int
WIN32_getrusage(int who, struct rusage *usage)
=======================================
--- /branches/LUSCA_HEAD/libiapp/Makefile.am Fri Jan 9 12:31:21 2009
+++ /branches/LUSCA_HEAD/libiapp/Makefile.am Mon Apr 5 05:15:45 2010
@@ -31,6 +31,12 @@
SSLSOURCE =
endif
+if ENABLE_WIN32SPECIFIC
+WIN32SOURCE = win32_pipe.c
+else
+WIN32SOURCE =
+endif
+
libiapp_a_SOURCES = \
fd.c \
comm.c \
@@ -45,7 +51,8 @@
comm_ips_tproxy4.c \
comm_ips_freebsd.c \
$(COMMLOOP_SOURCE) \
- $(SSLSOURCE)
+ $(SSLSOURCE) \
+ $(WIN32SOURCE)
noinst_LIBRARIES = \
libiapp.a
--
You received this message because you are subscribed to the Google Groups
"lusca-commit" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/lusca-commit?hl=en.