]> git.ipfire.org Git - thirdparty/squid.git/commitdiff
Summary: Windows FD support from Guido.
authorrobertc <>
Sun, 2 Feb 2003 20:27:43 +0000 (20:27 +0000)
committerrobertc <>
Sun, 2 Feb 2003 20:27:43 +0000 (20:27 +0000)
Keywords:

Hi,

This is the first of some splitted native Windows patches grouped by
functionality.

This patch add the native Windows support for the correct file and socket
FD handling methods.

Regards

Guido

src/SquidString.h [new file with mode: 0644]
src/fd.cc

diff --git a/src/SquidString.h b/src/SquidString.h
new file mode 100644 (file)
index 0000000..6d2e9b2
--- /dev/null
@@ -0,0 +1,87 @@
+
+/*
+ * $Id: SquidString.h,v 1.1 2003/02/02 13:27:43 robertc Exp $
+ *
+ * DEBUG: section 67    String
+ * AUTHOR: Duane Wessels
+ *
+ * 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.
+ *
+ */
+
+#ifndef SQUID_STRING_H
+#define SQUID_STRING_H
+
+class String {
+public:
+    static const String Null;
+    _SQUID_INLINE_ String();
+    String (char const *);
+    String (String const &);
+    ~String();
+    
+    String &operator =(char const *);
+    String &operator =(String const &);
+    
+    _SQUID_INLINE_ int size() const;
+    _SQUID_INLINE_ char const * buf() const;
+    void init (char const *);
+    void initBuf(size_t sz);
+    void limitInit(const char *str, int len);
+    void clean();
+    void reset(char const *str);
+    void append(char const *buf, int len);
+    void append(char const *buf);
+    void append (String const &);
+    void absorb(String &old);
+    _SQUID_INLINE_ int nCaseCmp (char const *aString, int aLen) const;
+private:
+    /* never reference these directly! */
+    unsigned short int size_;  /* buffer size; 64K limit */
+public:
+    unsigned short int len_;   /* current length  */
+    char *buf_;
+};
+
+#define StringNull String::Null;
+/* String */
+#define strChr(s,ch)  ((const char*)strchr((s).buf(), (ch)))
+#define strRChr(s,ch) ((const char*)strrchr((s).buf(), (ch)))
+#define strStr(s,str) ((const char*)strstr((s).buf(), (str)))
+#define strCmp(s,str)     strcmp((s).buf(), (str))
+#define strNCmp(s,str,n)     strncmp((s).buf(), (str), (n))
+#define strCaseCmp(s,str) strcasecmp((s).buf(), (str))
+#define strSet(s,ptr,ch) (s).buf_[ptr-(s).buf_] = (ch)
+#define strCut(s,pos) (((s).len_ = pos) , ((s).buf_[pos] = '\0'))
+#define strCutPtr(s,ptr) (((s).len_ = (ptr)-(s).buf_) , ((s).buf_[(s).len_] = '\0'))
+
+#ifdef _USE_INLINE_
+#include "String.cci"
+#endif
+
+#endif /* SQUID_STRING_H */
+
index 18f2ae28db7381ad8a3578b5be0bedd9ea308134..c3cbe32b1ecb44ffcd16c450511aa7e577bd4027 100644 (file)
--- a/src/fd.cc
+++ b/src/fd.cc
@@ -1,6 +1,6 @@
 
 /*
- * $Id: fd.cc,v 1.46 2003/01/23 00:37:20 robertc Exp $
+ * $Id: fd.cc,v 1.47 2003/02/02 13:27:43 robertc Exp $
  *
  * DEBUG: section 51    Filedescriptor Functions
  * AUTHOR: Duane Wessels
 
 int default_read_method(int, char *, int);
 int default_write_method(int, const char *, int);
+#ifdef _SQUID_MSWIN_
+int socket_read_method(int, char *, int);
+int socket_write_method(int, const char *, int);
+int file_read_method(int, char *, int);
+int file_write_method(int, const char *, int);
+#endif
 
 const char *fdTypeStr[] =
 {
@@ -94,6 +100,32 @@ fd_close(int fd)
     F->timeout = 0;
 }
 
+#ifdef _SQUID_MSWIN_
+
+int
+socket_read_method(int fd, char *buf, int len)
+{
+    return (recv(fd, buf, len, 0));
+}
+
+int
+file_read_method(int fd, char *buf, int len)
+{
+    return (_read(fd, buf, len));
+}
+
+int
+socket_write_method(int fd, const char *buf, int len)
+{
+    return (send(fd, buf, len, 0));
+}
+
+int
+file_write_method(int fd, const char *buf, int len)
+{
+    return (_write(fd, buf, len));
+}
+#else
 int
 default_read_method(int fd, char *buf, int len)
 {
@@ -105,6 +137,7 @@ default_write_method(int fd, const char *buf, int len)
 {
     return (write(fd, buf, len));
 }
+#endif
 
 void
 fd_open(int fd, unsigned int type, const char *desc)
@@ -120,8 +153,25 @@ fd_open(int fd, unsigned int type, const char *desc)
     debug(51, 3) ("fd_open FD %d %s\n", fd, desc);
     F->type = type;
     F->flags.open = 1;
+#ifdef _SQUID_MSWIN_
+    switch (type) {
+    case FD_SOCKET:
+    case FD_PIPE:
+       F->read_method = &socket_read_method;
+       F->write_method = &socket_write_method;
+       break;
+    case FD_FILE:
+    case FD_LOG:
+       F->read_method = &file_read_method;
+       F->write_method = &file_write_method;
+       break;
+    default:
+       fatalf("fd_open(): unknown FD type - FD#: %i, type: %u, desc %s\n", fd, type, desc);
+    }
+#else
     F->read_method = &default_read_method;
     F->write_method = &default_write_method;
+#endif
     fdUpdateBiggest(fd, 1);
     if (desc)
        xstrncpy(F->desc, desc, FD_DESC_SZ);