Browse Source

Restoring authorship annotation for <dldmitry@yandex-team.ru>. Commit 2 of 2.

dldmitry 3 years ago
parent
commit
7b11682e84

+ 27 - 27
build/rules/go/vendor.policy

@@ -139,7 +139,7 @@ ALLOW .* -> vendor/github.com/aws/aws-sdk-go/service/sts
 ALLOW .* -> vendor/github.com/BurntSushi/toml
 
 # helpers for data sizes (kilobytes, petabytes), human readable sizes, parsing
-ALLOW .* -> vendor/github.com/c2h5oh/datasize 
+ALLOW .* -> vendor/github.com/c2h5oh/datasize
 
 # Disable tests because testdata won't fit into arcadia commit.
 DENY .* -> vendor/github.com/go-git/go-git/v5/storage/test
@@ -170,7 +170,7 @@ ALLOW .* -> vendor/github.com/coreos/go-systemd/v22/journal
 ALLOW .* -> vendor/github.com/coreos/go-systemd/v22/dbus
 
 # mocking for database/sql
-ALLOW .* -> vendor/github.com/DATA-DOG/go-sqlmock 
+ALLOW .* -> vendor/github.com/DATA-DOG/go-sqlmock
 
 # Cucumber-like BDD for Go
 ## New location
@@ -179,7 +179,7 @@ ALLOW .* -> vendor/github.com/cucumber/godog
 ALLOW .* -> vendor/github.com/DATA-DOG/godog
 
 # pretty printer for GO
-ALLOW .* -> vendor/github.com/davecgh/go-spew/spew 
+ALLOW .* -> vendor/github.com/davecgh/go-spew/spew
 
 # CONTRIB-425 implementation of JSON Web Tokens (JWT)
 ALLOW .* -> vendor/github.com/golang-jwt/jwt
@@ -194,7 +194,7 @@ ALLOW .* -> vendor/github.com/docker/docker/api
 ALLOW .* -> vendor/github.com/docker/go-connections
 
 # cross-platform file system notifications
-ALLOW .* -> vendor/github.com/fsnotify/fsnotify 
+ALLOW .* -> vendor/github.com/fsnotify/fsnotify
 
 # lightweight, idiomatic and composable router
 ALLOW .* -> vendor/github.com/go-chi/chi/v5
@@ -209,10 +209,10 @@ ALLOW .* -> vendor/github.com/denisenkom/go-mssqldb
 ALLOW .* -> vendor/github.com/gofrs/flock
 
 # a pure Go implementation of Universally Unique Identifiers
-ALLOW .* -> vendor/github.com/gofrs/uuid 
+ALLOW .* -> vendor/github.com/gofrs/uuid
 
 # websocket protocol
-ALLOW .* -> vendor/github.com/gorilla/websocket 
+ALLOW .* -> vendor/github.com/gorilla/websocket
 
 # http sessions with cookie and filesystem session storage
 ALLOW .* -> vendor/github.com/gorilla/sessions
@@ -224,7 +224,7 @@ ALLOW .* -> vendor/github.com/gorilla/schema
 ALLOW .* -> vendor/github.com/golang/geo
 
 # snappy compression
-ALLOW .* -> vendor/github.com/golang/snappy 
+ALLOW .* -> vendor/github.com/golang/snappy
 
 # CONTRIB-632, CONTRIB-1992 API for sentry
 DENY .* -> vendor/github.com/AndreasBriese/bbloom;test
@@ -240,7 +240,7 @@ DENY .* -> vendor/github.com/rs/cors/examples
 DENY .* -> vendor/github.com/rs/cors/wrapper/gin
 
 ALLOW .* -> vendor/github.com/getsentry/sentry-go
-ALLOW .* -> vendor/github.com/getsentry/raven-go 
+ALLOW .* -> vendor/github.com/getsentry/raven-go
 
 # configuration library
 ALLOW .* -> vendor/github.com/heetch/confita
@@ -282,22 +282,22 @@ ALLOW .* -> vendor/github.com/ClickHouse/clickhouse-go
 ALLOW .* -> vendor/github.com/labstack/echo/v4
 
 # fluent SQL builder
-ALLOW .* -> vendor/github.com/Masterminds/squirrel 
+ALLOW .* -> vendor/github.com/Masterminds/squirrel
 
 # isatty for golang
-ALLOW .* -> vendor/github.com/mattn/go-isatty 
+ALLOW .* -> vendor/github.com/mattn/go-isatty
 
 # go-sqlite3 for golang
 ALLOW .* -> vendor/github.com/mattn/go-sqlite3
 
 # complete and usable DNS library
-ALLOW .* -> vendor/github.com/miekg/dns 
+ALLOW .* -> vendor/github.com/miekg/dns
 
 # deep copying values
-ALLOW .* -> vendor/github.com/mitchellh/copystructure 
+ALLOW .* -> vendor/github.com/mitchellh/copystructure
 
 # decoding generic map values to structures and vice versa
-ALLOW .* -> vendor/github.com/mitchellh/mapstructure 
+ALLOW .* -> vendor/github.com/mitchellh/mapstructure
 
 # library for detecting and expanding the user's home directory without cgo
 ALLOW .* -> vendor/github.com/mitchellh/go-homedir
@@ -306,7 +306,7 @@ ALLOW .* -> vendor/github.com/mitchellh/go-homedir
 ALLOW .* -> vendor/github.com/montanaflynn/stats
 
 # runtime dependencies of go-swagger
-ALLOW .* -> vendor/github.com/go-openapi 
+ALLOW .* -> vendor/github.com/go-openapi
 
 # CONTRIB-469: swagger code generator for both client and server
 ALLOW .* -> vendor/github.com/go-swagger/go-swagger/cmd/swagger
@@ -321,10 +321,10 @@ ALLOW .* -> vendor/github.com/google/go-github/v35/github
 ALLOW .* -> vendor/github.com/mailru/easyjson
 
 # lz4 compression codec
-ALLOW .* -> vendor/github.com/pierrec/lz4 
+ALLOW .* -> vendor/github.com/pierrec/lz4
 
 # library for HTML DOM manipulations and searching nodes by CSS selectors
-ALLOW .* -> vendor/github.com/PuerkitoBio/goquery 
+ALLOW .* -> vendor/github.com/PuerkitoBio/goquery
 
 # prometheus client
 ALLOW .* -> vendor/github.com/prometheus/client_golang
@@ -344,22 +344,22 @@ ALLOW .* -> vendor/github.com/slack-go/slack
 ALLOW .* -> vendor/github.com/pmezard/go-difflib
 
 # statsd client library
-ALLOW .* -> vendor/github.com/smira/go-statsd 
+ALLOW .* -> vendor/github.com/smira/go-statsd
 
 # ICMP Ping library
 ALLOW .* -> vendor/github.com/sparrc/go-ping
 
 # safe and easy casting from one type to another
-ALLOW .* -> vendor/github.com/spf13/cast 
+ALLOW .* -> vendor/github.com/spf13/cast
 
 # library for creating CLI applications
-ALLOW .* -> vendor/github.com/spf13/cobra 
+ALLOW .* -> vendor/github.com/spf13/cobra
 
 # drop-in replacement for stdlib flag module
-ALLOW .* -> vendor/github.com/spf13/pflag 
+ALLOW .* -> vendor/github.com/spf13/pflag
 
 # a toolkit with common test assertions and mocks
-ALLOW .* -> vendor/github.com/stretchr/testify 
+ALLOW .* -> vendor/github.com/stretchr/testify
 
 # very fast json parser and encoder.
 # uses dynamic message structure, suitable for cases where json structure is not known in advance.
@@ -369,7 +369,7 @@ ALLOW .* -> vendor/github.com/valyala/fastjson
 ALLOW .* -> vendor/github.com/OneOfOne/xxhash
 
 # default logging library. See also: library/go/core/log.
-ALLOW .* -> vendor/go.uber.org/zap 
+ALLOW .* -> vendor/go.uber.org/zap
 
 # package for writing logs to rolling files.
 ALLOW .* -> vendor/gopkg.in/natefinch/lumberjack.v2
@@ -402,7 +402,7 @@ ALLOW .* -> vendor/golang.org/x/time
 ALLOW .* -> vendor/golang.org/x/image/webp
 
 # less experimental implementation of Go error inspection
-ALLOW .* -> vendor/golang.org/x/xerrors 
+ALLOW .* -> vendor/golang.org/x/xerrors
 
 # golang.org/x/sys required for SO_REUSEPORT, for example
 ALLOW .* -> vendor/golang.org/x/sys
@@ -410,7 +410,7 @@ ALLOW .* -> vendor/golang.org/x/sys
 ALLOW .* -> vendor/golang.org/x/mod
 
 # basic LDAP v3 functionality for the GO programming language
-ALLOW .* -> vendor/gopkg.in/ldap.v3 
+ALLOW .* -> vendor/gopkg.in/ldap.v3
 
 # simple HTTP and REST client library
 ALLOW .* -> vendor/github.com/go-resty/resty/v2
@@ -492,9 +492,9 @@ ALLOW .* -> vendor/github.com/hashicorp/golang-lru
 # A wrapper around os/exec.Cmd to run external commands asynchronously (for Linux and macOS)
 ALLOW .* -> vendor/github.com/go-cmd/cmd
 
-# NVIDIA Management Library (NVML) is a C-based API for monitoring and managing NVIDIA GPU devices (for Linux only) 
-ALLOW .* -> vendor/github.com/NVIDIA/gpu-monitoring-tools/bindings/go 
- 
+# NVIDIA Management Library (NVML) is a C-based API for monitoring and managing NVIDIA GPU devices (for Linux only)
+ALLOW .* -> vendor/github.com/NVIDIA/gpu-monitoring-tools/bindings/go
+
 # Opentracing interface and implementation.
 ALLOW .* -> vendor/github.com/uber/jaeger-client-go
 ALLOW .* -> vendor/github.com/uber/jaeger-lib/metrics

+ 34 - 34
build/ya.conf.json

@@ -393,9 +393,9 @@
         "strace": {
             "description": "the linux syscall tracer"
         },
-        "iperf": { 
-            "description": "network load tester" 
-        }, 
+        "iperf": {
+            "description": "network load tester"
+        },
         "lkvm": {
             "description": "kvmtool is a userland tool for creating and controlling KVM guests"
         },
@@ -5104,22 +5104,22 @@
                 }
             ]
         },
-        "iperf": { 
-            "tools": { 
-                "iperf": { 
-                    "bottle": "iperf", 
-                    "executable": "iperf" 
-                } 
-            }, 
-            "platforms": [ 
-                { 
-                    "host": { 
-                        "os": "LINUX" 
-                    }, 
-                    "default": true 
-                } 
-            ] 
-        }, 
+        "iperf": {
+            "tools": {
+                "iperf": {
+                    "bottle": "iperf",
+                    "executable": "iperf"
+                }
+            },
+            "platforms": [
+                {
+                    "host": {
+                        "os": "LINUX"
+                    },
+                    "default": true
+                }
+            ]
+        },
         "lkvm": {
             "tools": {
                 "lkvm": {
@@ -7592,21 +7592,21 @@
                 ]
             }
         },
-        "iperf": { 
-            "formula": { 
-                "sandbox_id": [ 
-                    635087857 
-                ], 
-                "match": "infra/kernel/tools/iperf/build/iperf.tar.gz" 
-            }, 
-            "executable": { 
-                "iperf": [ 
-                    "iperf", 
-                    "bin", 
-                    "iperf3" 
-                ] 
-            } 
-        }, 
+        "iperf": {
+            "formula": {
+                "sandbox_id": [
+                    635087857
+                ],
+                "match": "infra/kernel/tools/iperf/build/iperf.tar.gz"
+            },
+            "executable": {
+                "iperf": [
+                    "iperf",
+                    "bin",
+                    "iperf3"
+                ]
+            }
+        },
         "kvmtool": {
             "formula": {
                 "sandbox_id": [

File diff suppressed because it is too large
+ 441 - 441
contrib/libs/libevent/ChangeLog


+ 74 - 74
contrib/libs/libevent/LICENSE

@@ -1,77 +1,77 @@
-Libevent is available for use under the following license, commonly known 
-as the 3-clause (or "modified") BSD license: 
- 
-============================== 
-Copyright (c) 2000-2007 Niels Provos <provos@citi.umich.edu> 
-Copyright (c) 2007-2012 Niels Provos and Nick Mathewson 
- 
-Redistribution and use in source and binary forms, with or without 
-modification, are permitted provided that the following conditions 
-are met: 
-1. Redistributions of source code must retain the above copyright 
-   notice, this list of conditions and the following disclaimer. 
-2. Redistributions in binary form must reproduce the above copyright 
-   notice, this list of conditions and the following disclaimer in the 
-   documentation and/or other materials provided with the distribution. 
-3. The name of the author may not be used to endorse or promote products 
-   derived from this software without specific prior written permission. 
- 
-THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 
-IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 
-OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 
-IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 
-INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 
-NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 
-DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 
-THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 
-(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 
-THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 
-============================== 
- 
-Portions of Libevent are based on works by others, also made available by 
-them under the three-clause BSD license above.  The copyright notices are 
-available in the corresponding source files; the license is as above.  Here's 
-a list: 
- 
-log.c: 
-   Copyright (c) 2000 Dug Song <dugsong@monkey.org> 
-   Copyright (c) 1993 The Regents of the University of California. 
- 
-strlcpy.c: 
-   Copyright (c) 1998 Todd C. Miller <Todd.Miller@courtesan.com> 
- 
-win32select.c: 
-   Copyright (c) 2003 Michael A. Davis <mike@datanerds.net> 
- 
-evport.c: 
-   Copyright (c) 2007 Sun Microsystems 
- 
-ht-internal.h: 
-   Copyright (c) 2002 Christopher Clark 
- 
-minheap-internal.h: 
-   Copyright (c) 2006 Maxim Yegorushkin <maxim.yegorushkin@gmail.com> 
- 
-============================== 
- 
-The arc4module is available under the following, sometimes called the 
-"OpenBSD" license: 
- 
-   Copyright (c) 1996, David Mazieres <dm@uun.org> 
-   Copyright (c) 2008, Damien Miller <djm@openbsd.org> 
- 
-   Permission to use, copy, modify, and distribute this software for any 
-   purpose with or without fee is hereby granted, provided that the above 
-   copyright notice and this permission notice appear in all copies. 
- 
-   THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES 
-   WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF 
-   MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR 
-   ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES 
-   WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN 
-   ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF 
-   OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 
- 
+Libevent is available for use under the following license, commonly known
+as the 3-clause (or "modified") BSD license:
+
+==============================
+Copyright (c) 2000-2007 Niels Provos <provos@citi.umich.edu>
+Copyright (c) 2007-2012 Niels Provos and Nick Mathewson
+
+Redistribution and use in source and binary forms, with or without
+modification, are permitted provided that the following conditions
+are met:
+1. Redistributions of source code must retain the above copyright
+   notice, this list of conditions and the following disclaimer.
+2. Redistributions in binary form must reproduce the above copyright
+   notice, this list of conditions and the following disclaimer in the
+   documentation and/or other materials provided with the distribution.
+3. The name of the author may not be used to endorse or promote products
+   derived from this software without specific prior written permission.
+
+THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
+IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
+INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
+THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+==============================
+
+Portions of Libevent are based on works by others, also made available by
+them under the three-clause BSD license above.  The copyright notices are
+available in the corresponding source files; the license is as above.  Here's
+a list:
+
+log.c:
+   Copyright (c) 2000 Dug Song <dugsong@monkey.org>
+   Copyright (c) 1993 The Regents of the University of California.
+
+strlcpy.c:
+   Copyright (c) 1998 Todd C. Miller <Todd.Miller@courtesan.com>
+
+win32select.c:
+   Copyright (c) 2003 Michael A. Davis <mike@datanerds.net>
+
+evport.c:
+   Copyright (c) 2007 Sun Microsystems
+
+ht-internal.h:
+   Copyright (c) 2002 Christopher Clark
+
+minheap-internal.h:
+   Copyright (c) 2006 Maxim Yegorushkin <maxim.yegorushkin@gmail.com>
+
+==============================
+
+The arc4module is available under the following, sometimes called the
+"OpenBSD" license:
+
+   Copyright (c) 1996, David Mazieres <dm@uun.org>
+   Copyright (c) 2008, Damien Miller <djm@openbsd.org>
+
+   Permission to use, copy, modify, and distribute this software for any
+   purpose with or without fee is hereby granted, provided that the above
+   copyright notice and this permission notice appear in all copies.
+
+   THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
+   WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
+   MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
+   ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
+   WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
+   ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
+   OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
+
 ==============================
 
 The Windows timer code is based on code from libutp, which is

+ 508 - 508
contrib/libs/libevent/arc4random.c

@@ -1,546 +1,546 @@
-/* Portable arc4random.c based on arc4random.c from OpenBSD. 
- * Portable version by Chris Davis, adapted for Libevent by Nick Mathewson 
- * Copyright (c) 2010 Chris Davis, Niels Provos, and Nick Mathewson 
- * Copyright (c) 2010-2012 Niels Provos and Nick Mathewson 
- * 
- * Note that in Libevent, this file isn't compiled directly.  Instead, 
- * it's included from evutil_rand.c 
- */ 
- 
-/* 
- * Copyright (c) 1996, David Mazieres <dm@uun.org> 
- * Copyright (c) 2008, Damien Miller <djm@openbsd.org> 
- * 
- * Permission to use, copy, modify, and distribute this software for any 
- * purpose with or without fee is hereby granted, provided that the above 
- * copyright notice and this permission notice appear in all copies. 
- * 
- * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES 
- * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF 
- * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR 
- * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES 
- * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN 
- * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF 
- * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 
- */ 
- 
-/* 
- * Arc4 random number generator for OpenBSD. 
- * 
- * This code is derived from section 17.1 of Applied Cryptography, 
- * second edition, which describes a stream cipher allegedly 
- * compatible with RSA Labs "RC4" cipher (the actual description of 
- * which is a trade secret).  The same algorithm is used as a stream 
- * cipher called "arcfour" in Tatu Ylonen's ssh package. 
- * 
- * Here the stream cipher has been modified always to include the time 
- * when initializing the state.  That makes it impossible to 
- * regenerate the same random sequence twice, so this can't be used 
- * for encryption, but will generate good random numbers. 
- * 
- * RC4 is a registered trademark of RSA Laboratories. 
- */ 
- 
-#ifndef ARC4RANDOM_EXPORT 
-#define ARC4RANDOM_EXPORT 
-#endif 
- 
-#ifndef ARC4RANDOM_UINT32 
-#define ARC4RANDOM_UINT32 uint32_t 
-#endif 
- 
-#ifndef ARC4RANDOM_NO_INCLUDES 
+/* Portable arc4random.c based on arc4random.c from OpenBSD.
+ * Portable version by Chris Davis, adapted for Libevent by Nick Mathewson
+ * Copyright (c) 2010 Chris Davis, Niels Provos, and Nick Mathewson
+ * Copyright (c) 2010-2012 Niels Provos and Nick Mathewson
+ *
+ * Note that in Libevent, this file isn't compiled directly.  Instead,
+ * it's included from evutil_rand.c
+ */
+
+/*
+ * Copyright (c) 1996, David Mazieres <dm@uun.org>
+ * Copyright (c) 2008, Damien Miller <djm@openbsd.org>
+ *
+ * Permission to use, copy, modify, and distribute this software for any
+ * purpose with or without fee is hereby granted, provided that the above
+ * copyright notice and this permission notice appear in all copies.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
+ * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
+ * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
+ * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
+ * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
+ * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
+ * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
+ */
+
+/*
+ * Arc4 random number generator for OpenBSD.
+ *
+ * This code is derived from section 17.1 of Applied Cryptography,
+ * second edition, which describes a stream cipher allegedly
+ * compatible with RSA Labs "RC4" cipher (the actual description of
+ * which is a trade secret).  The same algorithm is used as a stream
+ * cipher called "arcfour" in Tatu Ylonen's ssh package.
+ *
+ * Here the stream cipher has been modified always to include the time
+ * when initializing the state.  That makes it impossible to
+ * regenerate the same random sequence twice, so this can't be used
+ * for encryption, but will generate good random numbers.
+ *
+ * RC4 is a registered trademark of RSA Laboratories.
+ */
+
+#ifndef ARC4RANDOM_EXPORT
+#define ARC4RANDOM_EXPORT
+#endif
+
+#ifndef ARC4RANDOM_UINT32
+#define ARC4RANDOM_UINT32 uint32_t
+#endif
+
+#ifndef ARC4RANDOM_NO_INCLUDES
 #include "evconfig-private.h"
 #ifdef _WIN32
-#include <wincrypt.h> 
-#include <process.h> 
+#include <wincrypt.h>
+#include <process.h>
 #include <winerror.h>
-#else 
-#include <fcntl.h> 
-#include <unistd.h> 
-#include <sys/param.h> 
-#include <sys/time.h> 
+#else
+#include <fcntl.h>
+#include <unistd.h>
+#include <sys/param.h>
+#include <sys/time.h>
 #ifdef EVENT__HAVE_SYS_SYSCTL_H
-#include <sys/sysctl.h> 
-#endif 
+#include <sys/sysctl.h>
+#endif
 #ifdef EVENT__HAVE_SYS_RANDOM_H
 #include <sys/random.h>
-#endif 
 #endif
-#include <limits.h> 
-#include <stdlib.h> 
-#include <string.h> 
-#endif 
- 
-/* Add platform entropy 32 bytes (256 bits) at a time. */ 
-#define ADD_ENTROPY 32 
- 
-/* Re-seed from the platform RNG after generating this many bytes. */ 
-#define BYTES_BEFORE_RESEED 1600000 
- 
-struct arc4_stream { 
-	unsigned char i; 
-	unsigned char j; 
-	unsigned char s[256]; 
-}; 
- 
+#endif
+#include <limits.h>
+#include <stdlib.h>
+#include <string.h>
+#endif
+
+/* Add platform entropy 32 bytes (256 bits) at a time. */
+#define ADD_ENTROPY 32
+
+/* Re-seed from the platform RNG after generating this many bytes. */
+#define BYTES_BEFORE_RESEED 1600000
+
+struct arc4_stream {
+	unsigned char i;
+	unsigned char j;
+	unsigned char s[256];
+};
+
 #ifdef _WIN32
-#define getpid _getpid 
-#define pid_t int 
-#endif 
- 
-static int rs_initialized; 
-static struct arc4_stream rs; 
-static pid_t arc4_stir_pid; 
-static int arc4_count; 
- 
-static inline unsigned char arc4_getbyte(void); 
- 
-static inline void 
-arc4_init(void) 
-{ 
-	int     n; 
- 
-	for (n = 0; n < 256; n++) 
-		rs.s[n] = n; 
-	rs.i = 0; 
-	rs.j = 0; 
-} 
- 
-static inline void 
-arc4_addrandom(const unsigned char *dat, int datlen) 
-{ 
-	int     n; 
-	unsigned char si; 
- 
-	rs.i--; 
-	for (n = 0; n < 256; n++) { 
-		rs.i = (rs.i + 1); 
-		si = rs.s[rs.i]; 
-		rs.j = (rs.j + si + dat[n % datlen]); 
-		rs.s[rs.i] = rs.s[rs.j]; 
-		rs.s[rs.j] = si; 
-	} 
-	rs.j = rs.i; 
-} 
- 
+#define getpid _getpid
+#define pid_t int
+#endif
+
+static int rs_initialized;
+static struct arc4_stream rs;
+static pid_t arc4_stir_pid;
+static int arc4_count;
+
+static inline unsigned char arc4_getbyte(void);
+
+static inline void
+arc4_init(void)
+{
+	int     n;
+
+	for (n = 0; n < 256; n++)
+		rs.s[n] = n;
+	rs.i = 0;
+	rs.j = 0;
+}
+
+static inline void
+arc4_addrandom(const unsigned char *dat, int datlen)
+{
+	int     n;
+	unsigned char si;
+
+	rs.i--;
+	for (n = 0; n < 256; n++) {
+		rs.i = (rs.i + 1);
+		si = rs.s[rs.i];
+		rs.j = (rs.j + si + dat[n % datlen]);
+		rs.s[rs.i] = rs.s[rs.j];
+		rs.s[rs.j] = si;
+	}
+	rs.j = rs.i;
+}
+
 #ifndef _WIN32
-static ssize_t 
-read_all(int fd, unsigned char *buf, size_t count) 
-{ 
-	size_t numread = 0; 
-	ssize_t result; 
- 
-	while (numread < count) { 
-		result = read(fd, buf+numread, count-numread); 
-		if (result<0) 
-			return -1; 
-		else if (result == 0) 
-			break; 
-		numread += result; 
-	} 
- 
-	return (ssize_t)numread; 
-} 
-#endif 
- 
+static ssize_t
+read_all(int fd, unsigned char *buf, size_t count)
+{
+	size_t numread = 0;
+	ssize_t result;
+
+	while (numread < count) {
+		result = read(fd, buf+numread, count-numread);
+		if (result<0)
+			return -1;
+		else if (result == 0)
+			break;
+		numread += result;
+	}
+
+	return (ssize_t)numread;
+}
+#endif
+
 #ifdef _WIN32
-#define TRY_SEED_WIN32 
-static int 
-arc4_seed_win32(void) 
-{ 
-	/* This is adapted from Tor's crypto_seed_rng() */ 
-	static int provider_set = 0; 
-	static HCRYPTPROV provider; 
-	unsigned char buf[ADD_ENTROPY]; 
- 
-	if (!provider_set) { 
-		if (!CryptAcquireContext(&provider, NULL, NULL, PROV_RSA_FULL, 
-		    CRYPT_VERIFYCONTEXT)) { 
-			if (GetLastError() != (DWORD)NTE_BAD_KEYSET) 
-				return -1; 
-		} 
-		provider_set = 1; 
-	} 
-	if (!CryptGenRandom(provider, sizeof(buf), buf)) 
-		return -1; 
-	arc4_addrandom(buf, sizeof(buf)); 
-	evutil_memclear_(buf, sizeof(buf)); 
-	return 0; 
-} 
-#endif 
- 
+#define TRY_SEED_WIN32
+static int
+arc4_seed_win32(void)
+{
+	/* This is adapted from Tor's crypto_seed_rng() */
+	static int provider_set = 0;
+	static HCRYPTPROV provider;
+	unsigned char buf[ADD_ENTROPY];
+
+	if (!provider_set) {
+		if (!CryptAcquireContext(&provider, NULL, NULL, PROV_RSA_FULL,
+		    CRYPT_VERIFYCONTEXT)) {
+			if (GetLastError() != (DWORD)NTE_BAD_KEYSET)
+				return -1;
+		}
+		provider_set = 1;
+	}
+	if (!CryptGenRandom(provider, sizeof(buf), buf))
+		return -1;
+	arc4_addrandom(buf, sizeof(buf));
+	evutil_memclear_(buf, sizeof(buf));
+	return 0;
+}
+#endif
+
 #if defined(EVENT__HAVE_GETRANDOM)
 #define TRY_SEED_GETRANDOM
-static int 
+static int
 arc4_seed_getrandom(void)
-{ 
-	unsigned char buf[ADD_ENTROPY]; 
-	size_t len, n; 
-	unsigned i; 
-	int any_set; 
- 
-	memset(buf, 0, sizeof(buf)); 
- 
-	for (len = 0; len < sizeof(buf); len += n) { 
-		n = sizeof(buf) - len; 
- 
+{
+	unsigned char buf[ADD_ENTROPY];
+	size_t len, n;
+	unsigned i;
+	int any_set;
+
+	memset(buf, 0, sizeof(buf));
+
+	for (len = 0; len < sizeof(buf); len += n) {
+		n = sizeof(buf) - len;
+
 		if (0 == getrandom(&buf[len], n, 0))
-			return -1; 
-	} 
-	/* make sure that the buffer actually got set. */ 
-	for (i=0,any_set=0; i<sizeof(buf); ++i) { 
-		any_set |= buf[i]; 
-	} 
-	if (!any_set) 
-		return -1; 
- 
-	arc4_addrandom(buf, sizeof(buf)); 
-	evutil_memclear_(buf, sizeof(buf)); 
-	return 0; 
-} 
+			return -1;
+	}
+	/* make sure that the buffer actually got set. */
+	for (i=0,any_set=0; i<sizeof(buf); ++i) {
+		any_set |= buf[i];
+	}
+	if (!any_set)
+		return -1;
+
+	arc4_addrandom(buf, sizeof(buf));
+	evutil_memclear_(buf, sizeof(buf));
+	return 0;
+}
 #endif /* EVENT__HAVE_GETRANDOM */
- 
+
 #if defined(EVENT__HAVE_SYS_SYSCTL_H) && defined(EVENT__HAVE_SYSCTL)
 #if EVENT__HAVE_DECL_CTL_KERN && EVENT__HAVE_DECL_KERN_ARND
-#define TRY_SEED_SYSCTL_BSD 
-static int 
-arc4_seed_sysctl_bsd(void) 
-{ 
-	/* Based on code from William Ahern and from OpenBSD, this function 
-	 * tries to use the KERN_ARND syscall to get entropy from the kernel. 
-	 * This can work even if /dev/urandom is inaccessible for some reason 
-	 * (e.g., we're running in a chroot). */ 
-	int mib[] = { CTL_KERN, KERN_ARND }; 
-	unsigned char buf[ADD_ENTROPY]; 
-	size_t len, n; 
-	int i, any_set; 
- 
-	memset(buf, 0, sizeof(buf)); 
- 
-	len = sizeof(buf); 
-	if (sysctl(mib, 2, buf, &len, NULL, 0) == -1) { 
-		for (len = 0; len < sizeof(buf); len += sizeof(unsigned)) { 
-			n = sizeof(unsigned); 
-			if (n + len > sizeof(buf)) 
-			    n = len - sizeof(buf); 
-			if (sysctl(mib, 2, &buf[len], &n, NULL, 0) == -1) 
-				return -1; 
-		} 
-	} 
-	/* make sure that the buffer actually got set. */ 
-	for (i=any_set=0; i<sizeof(buf); ++i) { 
-		any_set |= buf[i]; 
-	} 
-	if (!any_set) 
-		return -1; 
- 
-	arc4_addrandom(buf, sizeof(buf)); 
-	evutil_memclear_(buf, sizeof(buf)); 
-	return 0; 
-} 
-#endif 
+#define TRY_SEED_SYSCTL_BSD
+static int
+arc4_seed_sysctl_bsd(void)
+{
+	/* Based on code from William Ahern and from OpenBSD, this function
+	 * tries to use the KERN_ARND syscall to get entropy from the kernel.
+	 * This can work even if /dev/urandom is inaccessible for some reason
+	 * (e.g., we're running in a chroot). */
+	int mib[] = { CTL_KERN, KERN_ARND };
+	unsigned char buf[ADD_ENTROPY];
+	size_t len, n;
+	int i, any_set;
+
+	memset(buf, 0, sizeof(buf));
+
+	len = sizeof(buf);
+	if (sysctl(mib, 2, buf, &len, NULL, 0) == -1) {
+		for (len = 0; len < sizeof(buf); len += sizeof(unsigned)) {
+			n = sizeof(unsigned);
+			if (n + len > sizeof(buf))
+			    n = len - sizeof(buf);
+			if (sysctl(mib, 2, &buf[len], &n, NULL, 0) == -1)
+				return -1;
+		}
+	}
+	/* make sure that the buffer actually got set. */
+	for (i=any_set=0; i<sizeof(buf); ++i) {
+		any_set |= buf[i];
+	}
+	if (!any_set)
+		return -1;
+
+	arc4_addrandom(buf, sizeof(buf));
+	evutil_memclear_(buf, sizeof(buf));
+	return 0;
+}
+#endif
 #endif /* defined(EVENT__HAVE_SYS_SYSCTL_H) */
- 
-#ifdef __linux__ 
-#define TRY_SEED_PROC_SYS_KERNEL_RANDOM_UUID 
-static int 
-arc4_seed_proc_sys_kernel_random_uuid(void) 
-{ 
-	/* Occasionally, somebody will make /proc/sys accessible in a chroot, 
-	 * but not /dev/urandom.  Let's try /proc/sys/kernel/random/uuid. 
-	 * Its format is stupid, so we need to decode it from hex. 
-	 */ 
-	int fd; 
-	char buf[128]; 
-	unsigned char entropy[64]; 
-	int bytes, n, i, nybbles; 
-	for (bytes = 0; bytes<ADD_ENTROPY; ) { 
+
+#ifdef __linux__
+#define TRY_SEED_PROC_SYS_KERNEL_RANDOM_UUID
+static int
+arc4_seed_proc_sys_kernel_random_uuid(void)
+{
+	/* Occasionally, somebody will make /proc/sys accessible in a chroot,
+	 * but not /dev/urandom.  Let's try /proc/sys/kernel/random/uuid.
+	 * Its format is stupid, so we need to decode it from hex.
+	 */
+	int fd;
+	char buf[128];
+	unsigned char entropy[64];
+	int bytes, n, i, nybbles;
+	for (bytes = 0; bytes<ADD_ENTROPY; ) {
 		fd = evutil_open_closeonexec_("/proc/sys/kernel/random/uuid", O_RDONLY, 0);
-		if (fd < 0) 
-			return -1; 
-		n = read(fd, buf, sizeof(buf)); 
-		close(fd); 
-		if (n<=0) 
-			return -1; 
-		memset(entropy, 0, sizeof(entropy)); 
-		for (i=nybbles=0; i<n; ++i) { 
+		if (fd < 0)
+			return -1;
+		n = read(fd, buf, sizeof(buf));
+		close(fd);
+		if (n<=0)
+			return -1;
+		memset(entropy, 0, sizeof(entropy));
+		for (i=nybbles=0; i<n; ++i) {
 			if (EVUTIL_ISXDIGIT_(buf[i])) {
 				int nyb = evutil_hex_char_to_int_(buf[i]);
-				if (nybbles & 1) { 
-					entropy[nybbles/2] |= nyb; 
-				} else { 
-					entropy[nybbles/2] |= nyb<<4; 
-				} 
-				++nybbles; 
-			} 
-		} 
-		if (nybbles < 2) 
-			return -1; 
-		arc4_addrandom(entropy, nybbles/2); 
-		bytes += nybbles/2; 
-	} 
-	evutil_memclear_(entropy, sizeof(entropy)); 
-	evutil_memclear_(buf, sizeof(buf)); 
-	return 0; 
-} 
-#endif 
- 
+				if (nybbles & 1) {
+					entropy[nybbles/2] |= nyb;
+				} else {
+					entropy[nybbles/2] |= nyb<<4;
+				}
+				++nybbles;
+			}
+		}
+		if (nybbles < 2)
+			return -1;
+		arc4_addrandom(entropy, nybbles/2);
+		bytes += nybbles/2;
+	}
+	evutil_memclear_(entropy, sizeof(entropy));
+	evutil_memclear_(buf, sizeof(buf));
+	return 0;
+}
+#endif
+
 #ifndef _WIN32
-#define TRY_SEED_URANDOM 
-static char *arc4random_urandom_filename = NULL; 
- 
-static int arc4_seed_urandom_helper_(const char *fname) 
-{ 
-	unsigned char buf[ADD_ENTROPY]; 
-	int fd; 
-	size_t n; 
- 
+#define TRY_SEED_URANDOM
+static char *arc4random_urandom_filename = NULL;
+
+static int arc4_seed_urandom_helper_(const char *fname)
+{
+	unsigned char buf[ADD_ENTROPY];
+	int fd;
+	size_t n;
+
 	fd = evutil_open_closeonexec_(fname, O_RDONLY, 0);
-	if (fd<0) 
-		return -1; 
-	n = read_all(fd, buf, sizeof(buf)); 
-	close(fd); 
-	if (n != sizeof(buf)) 
-		return -1; 
-	arc4_addrandom(buf, sizeof(buf)); 
-	evutil_memclear_(buf, sizeof(buf)); 
-	return 0; 
-} 
- 
-static int 
-arc4_seed_urandom(void) 
-{ 
-	/* This is adapted from Tor's crypto_seed_rng() */ 
-	static const char *filenames[] = { 
-		"/dev/srandom", "/dev/urandom", "/dev/random", NULL 
-	}; 
-	int i; 
-	if (arc4random_urandom_filename) 
-		return arc4_seed_urandom_helper_(arc4random_urandom_filename); 
- 
-	for (i = 0; filenames[i]; ++i) { 
-		if (arc4_seed_urandom_helper_(filenames[i]) == 0) { 
-			return 0; 
-		} 
-	} 
- 
-	return -1; 
-} 
-#endif 
- 
-static int 
-arc4_seed(void) 
-{ 
-	int ok = 0; 
-	/* We try every method that might work, and don't give up even if one 
-	 * does seem to work.  There's no real harm in over-seeding, and if 
-	 * one of these sources turns out to be broken, that would be bad. */ 
-#ifdef TRY_SEED_WIN32 
-	if (0 == arc4_seed_win32()) 
-		ok = 1; 
-#endif 
+	if (fd<0)
+		return -1;
+	n = read_all(fd, buf, sizeof(buf));
+	close(fd);
+	if (n != sizeof(buf))
+		return -1;
+	arc4_addrandom(buf, sizeof(buf));
+	evutil_memclear_(buf, sizeof(buf));
+	return 0;
+}
+
+static int
+arc4_seed_urandom(void)
+{
+	/* This is adapted from Tor's crypto_seed_rng() */
+	static const char *filenames[] = {
+		"/dev/srandom", "/dev/urandom", "/dev/random", NULL
+	};
+	int i;
+	if (arc4random_urandom_filename)
+		return arc4_seed_urandom_helper_(arc4random_urandom_filename);
+
+	for (i = 0; filenames[i]; ++i) {
+		if (arc4_seed_urandom_helper_(filenames[i]) == 0) {
+			return 0;
+		}
+	}
+
+	return -1;
+}
+#endif
+
+static int
+arc4_seed(void)
+{
+	int ok = 0;
+	/* We try every method that might work, and don't give up even if one
+	 * does seem to work.  There's no real harm in over-seeding, and if
+	 * one of these sources turns out to be broken, that would be bad. */
+#ifdef TRY_SEED_WIN32
+	if (0 == arc4_seed_win32())
+		ok = 1;
+#endif
 #ifdef TRY_SEED_GETRANDOM
 	if (0 == arc4_seed_getrandom())
 		ok = 1;
 #endif
-#ifdef TRY_SEED_URANDOM 
-	if (0 == arc4_seed_urandom()) 
-		ok = 1; 
-#endif 
-#ifdef TRY_SEED_PROC_SYS_KERNEL_RANDOM_UUID 
-	if (arc4random_urandom_filename == NULL && 
-	    0 == arc4_seed_proc_sys_kernel_random_uuid()) 
-		ok = 1; 
-#endif 
-#ifdef TRY_SEED_SYSCTL_BSD 
-	if (0 == arc4_seed_sysctl_bsd()) 
-		ok = 1; 
-#endif 
-	return ok ? 0 : -1; 
-} 
- 
-static int 
-arc4_stir(void) 
-{ 
-	int     i; 
- 
-	if (!rs_initialized) { 
-		arc4_init(); 
-		rs_initialized = 1; 
-	} 
- 
+#ifdef TRY_SEED_URANDOM
+	if (0 == arc4_seed_urandom())
+		ok = 1;
+#endif
+#ifdef TRY_SEED_PROC_SYS_KERNEL_RANDOM_UUID
+	if (arc4random_urandom_filename == NULL &&
+	    0 == arc4_seed_proc_sys_kernel_random_uuid())
+		ok = 1;
+#endif
+#ifdef TRY_SEED_SYSCTL_BSD
+	if (0 == arc4_seed_sysctl_bsd())
+		ok = 1;
+#endif
+	return ok ? 0 : -1;
+}
+
+static int
+arc4_stir(void)
+{
+	int     i;
+
+	if (!rs_initialized) {
+		arc4_init();
+		rs_initialized = 1;
+	}
+
 	if (0 != arc4_seed())
-		return -1; 
- 
-	/* 
-	 * Discard early keystream, as per recommendations in 
-	 * "Weaknesses in the Key Scheduling Algorithm of RC4" by 
-	 * Scott Fluhrer, Itsik Mantin, and Adi Shamir. 
-	 * http://www.wisdom.weizmann.ac.il/~itsik/RC4/Papers/Rc4_ksa.ps 
-	 * 
-	 * Ilya Mironov's "(Not So) Random Shuffles of RC4" suggests that 
-	 * we drop at least 2*256 bytes, with 12*256 as a conservative 
-	 * value. 
-	 * 
-	 * RFC4345 says to drop 6*256. 
-	 * 
-	 * At least some versions of this code drop 4*256, in a mistaken 
-	 * belief that "words" in the Fluhrer/Mantin/Shamir paper refers 
-	 * to processor words. 
-	 * 
-	 * We add another sect to the cargo cult, and choose 12*256. 
-	 */ 
-	for (i = 0; i < 12*256; i++) 
-		(void)arc4_getbyte(); 
- 
-	arc4_count = BYTES_BEFORE_RESEED; 
- 
-	return 0; 
-} 
- 
- 
-static void 
-arc4_stir_if_needed(void) 
-{ 
-	pid_t pid = getpid(); 
- 
-	if (arc4_count <= 0 || !rs_initialized || arc4_stir_pid != pid) 
-	{ 
-		arc4_stir_pid = pid; 
-		arc4_stir(); 
-	} 
-} 
- 
-static inline unsigned char 
-arc4_getbyte(void) 
-{ 
-	unsigned char si, sj; 
- 
-	rs.i = (rs.i + 1); 
-	si = rs.s[rs.i]; 
-	rs.j = (rs.j + si); 
-	sj = rs.s[rs.j]; 
-	rs.s[rs.i] = sj; 
-	rs.s[rs.j] = si; 
-	return (rs.s[(si + sj) & 0xff]); 
-} 
- 
-static inline unsigned int 
-arc4_getword(void) 
-{ 
-	unsigned int val; 
- 
-	val = arc4_getbyte() << 24; 
-	val |= arc4_getbyte() << 16; 
-	val |= arc4_getbyte() << 8; 
-	val |= arc4_getbyte(); 
- 
-	return val; 
-} 
- 
-#ifndef ARC4RANDOM_NOSTIR 
-ARC4RANDOM_EXPORT int 
-arc4random_stir(void) 
-{ 
-	int val; 
+		return -1;
+
+	/*
+	 * Discard early keystream, as per recommendations in
+	 * "Weaknesses in the Key Scheduling Algorithm of RC4" by
+	 * Scott Fluhrer, Itsik Mantin, and Adi Shamir.
+	 * http://www.wisdom.weizmann.ac.il/~itsik/RC4/Papers/Rc4_ksa.ps
+	 *
+	 * Ilya Mironov's "(Not So) Random Shuffles of RC4" suggests that
+	 * we drop at least 2*256 bytes, with 12*256 as a conservative
+	 * value.
+	 *
+	 * RFC4345 says to drop 6*256.
+	 *
+	 * At least some versions of this code drop 4*256, in a mistaken
+	 * belief that "words" in the Fluhrer/Mantin/Shamir paper refers
+	 * to processor words.
+	 *
+	 * We add another sect to the cargo cult, and choose 12*256.
+	 */
+	for (i = 0; i < 12*256; i++)
+		(void)arc4_getbyte();
+
+	arc4_count = BYTES_BEFORE_RESEED;
+
+	return 0;
+}
+
+
+static void
+arc4_stir_if_needed(void)
+{
+	pid_t pid = getpid();
+
+	if (arc4_count <= 0 || !rs_initialized || arc4_stir_pid != pid)
+	{
+		arc4_stir_pid = pid;
+		arc4_stir();
+	}
+}
+
+static inline unsigned char
+arc4_getbyte(void)
+{
+	unsigned char si, sj;
+
+	rs.i = (rs.i + 1);
+	si = rs.s[rs.i];
+	rs.j = (rs.j + si);
+	sj = rs.s[rs.j];
+	rs.s[rs.i] = sj;
+	rs.s[rs.j] = si;
+	return (rs.s[(si + sj) & 0xff]);
+}
+
+static inline unsigned int
+arc4_getword(void)
+{
+	unsigned int val;
+
+	val = arc4_getbyte() << 24;
+	val |= arc4_getbyte() << 16;
+	val |= arc4_getbyte() << 8;
+	val |= arc4_getbyte();
+
+	return val;
+}
+
+#ifndef ARC4RANDOM_NOSTIR
+ARC4RANDOM_EXPORT int
+arc4random_stir(void)
+{
+	int val;
 	ARC4_LOCK_();
-	val = arc4_stir(); 
+	val = arc4_stir();
 	ARC4_UNLOCK_();
-	return val; 
-} 
-#endif 
- 
-#ifndef ARC4RANDOM_NOADDRANDOM 
-ARC4RANDOM_EXPORT void 
-arc4random_addrandom(const unsigned char *dat, int datlen) 
-{ 
-	int j; 
+	return val;
+}
+#endif
+
+#ifndef ARC4RANDOM_NOADDRANDOM
+ARC4RANDOM_EXPORT void
+arc4random_addrandom(const unsigned char *dat, int datlen)
+{
+	int j;
 	ARC4_LOCK_();
-	if (!rs_initialized) 
-		arc4_stir(); 
-	for (j = 0; j < datlen; j += 256) { 
-		/* arc4_addrandom() ignores all but the first 256 bytes of 
-		 * its input.  We want to make sure to look at ALL the 
-		 * data in 'dat', just in case the user is doing something 
-		 * crazy like passing us all the files in /var/log. */ 
-		arc4_addrandom(dat + j, datlen - j); 
-	} 
+	if (!rs_initialized)
+		arc4_stir();
+	for (j = 0; j < datlen; j += 256) {
+		/* arc4_addrandom() ignores all but the first 256 bytes of
+		 * its input.  We want to make sure to look at ALL the
+		 * data in 'dat', just in case the user is doing something
+		 * crazy like passing us all the files in /var/log. */
+		arc4_addrandom(dat + j, datlen - j);
+	}
 	ARC4_UNLOCK_();
-} 
-#endif 
- 
-#ifndef ARC4RANDOM_NORANDOM 
-ARC4RANDOM_EXPORT ARC4RANDOM_UINT32 
-arc4random(void) 
-{ 
-	ARC4RANDOM_UINT32 val; 
+}
+#endif
+
+#ifndef ARC4RANDOM_NORANDOM
+ARC4RANDOM_EXPORT ARC4RANDOM_UINT32
+arc4random(void)
+{
+	ARC4RANDOM_UINT32 val;
 	ARC4_LOCK_();
-	arc4_count -= 4; 
-	arc4_stir_if_needed(); 
-	val = arc4_getword(); 
+	arc4_count -= 4;
+	arc4_stir_if_needed();
+	val = arc4_getword();
 	ARC4_UNLOCK_();
-	return val; 
-} 
-#endif 
- 
-ARC4RANDOM_EXPORT void 
+	return val;
+}
+#endif
+
+ARC4RANDOM_EXPORT void
 arc4random_buf(void *buf_, size_t n)
-{ 
+{
 	unsigned char *buf = buf_;
 	ARC4_LOCK_();
-	arc4_stir_if_needed(); 
-	while (n--) { 
-		if (--arc4_count <= 0) 
-			arc4_stir(); 
-		buf[n] = arc4_getbyte(); 
-	} 
+	arc4_stir_if_needed();
+	while (n--) {
+		if (--arc4_count <= 0)
+			arc4_stir();
+		buf[n] = arc4_getbyte();
+	}
 	ARC4_UNLOCK_();
-} 
- 
-#ifndef ARC4RANDOM_NOUNIFORM 
-/* 
- * Calculate a uniformly distributed random number less than upper_bound 
- * avoiding "modulo bias". 
- * 
- * Uniformity is achieved by generating new random numbers until the one 
- * returned is outside the range [0, 2**32 % upper_bound).  This 
- * guarantees the selected random number will be inside 
- * [2**32 % upper_bound, 2**32) which maps back to [0, upper_bound) 
- * after reduction modulo upper_bound. 
- */ 
-ARC4RANDOM_EXPORT unsigned int 
-arc4random_uniform(unsigned int upper_bound) 
-{ 
-	ARC4RANDOM_UINT32 r, min; 
- 
-	if (upper_bound < 2) 
-		return 0; 
- 
-#if (UINT_MAX > 0xffffffffUL) 
-	min = 0x100000000UL % upper_bound; 
-#else 
-	/* Calculate (2**32 % upper_bound) avoiding 64-bit math */ 
-	if (upper_bound > 0x80000000) 
-		min = 1 + ~upper_bound;		/* 2**32 - upper_bound */ 
-	else { 
-		/* (2**32 - (x * 2)) % x == 2**32 % x when x <= 2**31 */ 
-		min = ((0xffffffff - (upper_bound * 2)) + 1) % upper_bound; 
-	} 
-#endif 
- 
-	/* 
-	 * This could theoretically loop forever but each retry has 
-	 * p > 0.5 (worst case, usually far better) of selecting a 
-	 * number inside the range we need, so it should rarely need 
-	 * to re-roll. 
-	 */ 
-	for (;;) { 
-		r = arc4random(); 
-		if (r >= min) 
-			break; 
-	} 
- 
-	return r % upper_bound; 
-} 
-#endif 
+}
+
+#ifndef ARC4RANDOM_NOUNIFORM
+/*
+ * Calculate a uniformly distributed random number less than upper_bound
+ * avoiding "modulo bias".
+ *
+ * Uniformity is achieved by generating new random numbers until the one
+ * returned is outside the range [0, 2**32 % upper_bound).  This
+ * guarantees the selected random number will be inside
+ * [2**32 % upper_bound, 2**32) which maps back to [0, upper_bound)
+ * after reduction modulo upper_bound.
+ */
+ARC4RANDOM_EXPORT unsigned int
+arc4random_uniform(unsigned int upper_bound)
+{
+	ARC4RANDOM_UINT32 r, min;
+
+	if (upper_bound < 2)
+		return 0;
+
+#if (UINT_MAX > 0xffffffffUL)
+	min = 0x100000000UL % upper_bound;
+#else
+	/* Calculate (2**32 % upper_bound) avoiding 64-bit math */
+	if (upper_bound > 0x80000000)
+		min = 1 + ~upper_bound;		/* 2**32 - upper_bound */
+	else {
+		/* (2**32 - (x * 2)) % x == 2**32 % x when x <= 2**31 */
+		min = ((0xffffffff - (upper_bound * 2)) + 1) % upper_bound;
+	}
+#endif
+
+	/*
+	 * This could theoretically loop forever but each retry has
+	 * p > 0.5 (worst case, usually far better) of selecting a
+	 * number inside the range we need, so it should rarely need
+	 * to re-roll.
+	 */
+	for (;;) {
+		r = arc4random();
+		if (r >= min)
+			break;
+	}
+
+	return r % upper_bound;
+}
+#endif

File diff suppressed because it is too large
+ 505 - 505
contrib/libs/libevent/buffer.c


+ 306 - 306
contrib/libs/libevent/buffer_iocp.c

@@ -1,327 +1,327 @@
-/* 
- * Copyright (c) 2009-2012 Niels Provos and Nick Mathewson 
- * 
- * Redistribution and use in source and binary forms, with or without 
- * modification, are permitted provided that the following conditions 
- * are met: 
- * 1. Redistributions of source code must retain the above copyright 
- *    notice, this list of conditions and the following disclaimer. 
- * 2. Redistributions in binary form must reproduce the above copyright 
- *    notice, this list of conditions and the following disclaimer in the 
- *    documentation and/or other materials provided with the distribution. 
- * 3. The name of the author may not be used to endorse or promote products 
- *    derived from this software without specific prior written permission. 
- * 
- * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 
- * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 
- * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 
- * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 
- * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 
- * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 
- * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 
- * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 
- * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 
- * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 
- */ 
- 
-/** 
-   @file buffer_iocp.c 
- 
-   This module implements overlapped read and write functions for evbuffer 
-   objects on Windows. 
-*/ 
+/*
+ * Copyright (c) 2009-2012 Niels Provos and Nick Mathewson
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ * 3. The name of the author may not be used to endorse or promote products
+ *    derived from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
+ * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+ * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+ * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
+ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+/**
+   @file buffer_iocp.c
+
+   This module implements overlapped read and write functions for evbuffer
+   objects on Windows.
+*/
 #include "event2/event-config.h"
 #include "evconfig-private.h"
- 
-#include "event2/buffer.h" 
-#include "event2/buffer_compat.h" 
-#include "event2/util.h" 
-#include "event2/thread.h" 
-#include "util-internal.h" 
-#include "evthread-internal.h" 
-#include "evbuffer-internal.h" 
-#include "iocp-internal.h" 
-#include "mm-internal.h" 
- 
-#include <winsock2.h> 
+
+#include "event2/buffer.h"
+#include "event2/buffer_compat.h"
+#include "event2/util.h"
+#include "event2/thread.h"
+#include "util-internal.h"
+#include "evthread-internal.h"
+#include "evbuffer-internal.h"
+#include "iocp-internal.h"
+#include "mm-internal.h"
+
+#include <winsock2.h>
 #include <winerror.h>
-#include <windows.h> 
-#include <stdio.h> 
- 
-#define MAX_WSABUFS 16 
- 
-/** An evbuffer that can handle overlapped IO. */ 
-struct evbuffer_overlapped { 
-	struct evbuffer buffer; 
-	/** The socket that we're doing overlapped IO on. */ 
-	evutil_socket_t fd; 
- 
-	/** pending I/O type */ 
-	unsigned read_in_progress : 1; 
-	unsigned write_in_progress : 1; 
- 
-	/** The first pinned chain in the buffer. */ 
-	struct evbuffer_chain *first_pinned; 
- 
-	/** How many chains are pinned; how many of the fields in buffers 
-	 * are we using. */ 
-	int n_buffers; 
-	WSABUF buffers[MAX_WSABUFS]; 
-}; 
- 
-/** Given an evbuffer, return the correponding evbuffer structure, or NULL if 
- * the evbuffer isn't overlapped. */ 
-static inline struct evbuffer_overlapped * 
-upcast_evbuffer(struct evbuffer *buf) 
-{ 
-	if (!buf || !buf->is_overlapped) 
-		return NULL; 
-	return EVUTIL_UPCAST(buf, struct evbuffer_overlapped, buffer); 
-} 
- 
-/** Unpin all the chains noted as pinned in 'eo'. */ 
-static void 
-pin_release(struct evbuffer_overlapped *eo, unsigned flag) 
-{ 
-	int i; 
-	struct evbuffer_chain *next, *chain = eo->first_pinned; 
- 
-	for (i = 0; i < eo->n_buffers; ++i) { 
-		EVUTIL_ASSERT(chain); 
-		next = chain->next; 
+#include <windows.h>
+#include <stdio.h>
+
+#define MAX_WSABUFS 16
+
+/** An evbuffer that can handle overlapped IO. */
+struct evbuffer_overlapped {
+	struct evbuffer buffer;
+	/** The socket that we're doing overlapped IO on. */
+	evutil_socket_t fd;
+
+	/** pending I/O type */
+	unsigned read_in_progress : 1;
+	unsigned write_in_progress : 1;
+
+	/** The first pinned chain in the buffer. */
+	struct evbuffer_chain *first_pinned;
+
+	/** How many chains are pinned; how many of the fields in buffers
+	 * are we using. */
+	int n_buffers;
+	WSABUF buffers[MAX_WSABUFS];
+};
+
+/** Given an evbuffer, return the correponding evbuffer structure, or NULL if
+ * the evbuffer isn't overlapped. */
+static inline struct evbuffer_overlapped *
+upcast_evbuffer(struct evbuffer *buf)
+{
+	if (!buf || !buf->is_overlapped)
+		return NULL;
+	return EVUTIL_UPCAST(buf, struct evbuffer_overlapped, buffer);
+}
+
+/** Unpin all the chains noted as pinned in 'eo'. */
+static void
+pin_release(struct evbuffer_overlapped *eo, unsigned flag)
+{
+	int i;
+	struct evbuffer_chain *next, *chain = eo->first_pinned;
+
+	for (i = 0; i < eo->n_buffers; ++i) {
+		EVUTIL_ASSERT(chain);
+		next = chain->next;
 		evbuffer_chain_unpin_(chain, flag);
-		chain = next; 
-	} 
-} 
- 
-void 
+		chain = next;
+	}
+}
+
+void
 evbuffer_commit_read_(struct evbuffer *evbuf, ev_ssize_t nBytes)
-{ 
-	struct evbuffer_overlapped *buf = upcast_evbuffer(evbuf); 
-	struct evbuffer_chain **chainp; 
-	size_t remaining, len; 
-	unsigned i; 
- 
-	EVBUFFER_LOCK(evbuf); 
-	EVUTIL_ASSERT(buf->read_in_progress && !buf->write_in_progress); 
-	EVUTIL_ASSERT(nBytes >= 0); /* XXXX Can this be false? */ 
- 
-	evbuffer_unfreeze(evbuf, 0); 
- 
-	chainp = evbuf->last_with_datap; 
-	if (!((*chainp)->flags & EVBUFFER_MEM_PINNED_R)) 
-		chainp = &(*chainp)->next; 
-	remaining = nBytes; 
-	for (i = 0; remaining > 0 && i < (unsigned)buf->n_buffers; ++i) { 
-		EVUTIL_ASSERT(*chainp); 
-		len = buf->buffers[i].len; 
-		if (remaining < len) 
-			len = remaining; 
-		(*chainp)->off += len; 
-		evbuf->last_with_datap = chainp; 
-		remaining -= len; 
-		chainp = &(*chainp)->next; 
-	} 
- 
-	pin_release(buf, EVBUFFER_MEM_PINNED_R); 
- 
-	buf->read_in_progress = 0; 
- 
-	evbuf->total_len += nBytes; 
-	evbuf->n_add_for_cb += nBytes; 
- 
+{
+	struct evbuffer_overlapped *buf = upcast_evbuffer(evbuf);
+	struct evbuffer_chain **chainp;
+	size_t remaining, len;
+	unsigned i;
+
+	EVBUFFER_LOCK(evbuf);
+	EVUTIL_ASSERT(buf->read_in_progress && !buf->write_in_progress);
+	EVUTIL_ASSERT(nBytes >= 0); /* XXXX Can this be false? */
+
+	evbuffer_unfreeze(evbuf, 0);
+
+	chainp = evbuf->last_with_datap;
+	if (!((*chainp)->flags & EVBUFFER_MEM_PINNED_R))
+		chainp = &(*chainp)->next;
+	remaining = nBytes;
+	for (i = 0; remaining > 0 && i < (unsigned)buf->n_buffers; ++i) {
+		EVUTIL_ASSERT(*chainp);
+		len = buf->buffers[i].len;
+		if (remaining < len)
+			len = remaining;
+		(*chainp)->off += len;
+		evbuf->last_with_datap = chainp;
+		remaining -= len;
+		chainp = &(*chainp)->next;
+	}
+
+	pin_release(buf, EVBUFFER_MEM_PINNED_R);
+
+	buf->read_in_progress = 0;
+
+	evbuf->total_len += nBytes;
+	evbuf->n_add_for_cb += nBytes;
+
 	evbuffer_invoke_callbacks_(evbuf);
- 
+
 	evbuffer_decref_and_unlock_(evbuf);
-} 
- 
-void 
+}
+
+void
 evbuffer_commit_write_(struct evbuffer *evbuf, ev_ssize_t nBytes)
-{ 
-	struct evbuffer_overlapped *buf = upcast_evbuffer(evbuf); 
- 
-	EVBUFFER_LOCK(evbuf); 
-	EVUTIL_ASSERT(buf->write_in_progress && !buf->read_in_progress); 
-	evbuffer_unfreeze(evbuf, 1); 
-	evbuffer_drain(evbuf, nBytes); 
-	pin_release(buf,EVBUFFER_MEM_PINNED_W); 
-	buf->write_in_progress = 0; 
+{
+	struct evbuffer_overlapped *buf = upcast_evbuffer(evbuf);
+
+	EVBUFFER_LOCK(evbuf);
+	EVUTIL_ASSERT(buf->write_in_progress && !buf->read_in_progress);
+	evbuffer_unfreeze(evbuf, 1);
+	evbuffer_drain(evbuf, nBytes);
+	pin_release(buf,EVBUFFER_MEM_PINNED_W);
+	buf->write_in_progress = 0;
 	evbuffer_decref_and_unlock_(evbuf);
-} 
- 
-struct evbuffer * 
+}
+
+struct evbuffer *
 evbuffer_overlapped_new_(evutil_socket_t fd)
-{ 
-	struct evbuffer_overlapped *evo; 
- 
-	evo = mm_calloc(1, sizeof(struct evbuffer_overlapped)); 
-	if (!evo) 
-		return NULL; 
- 
+{
+	struct evbuffer_overlapped *evo;
+
+	evo = mm_calloc(1, sizeof(struct evbuffer_overlapped));
+	if (!evo)
+		return NULL;
+
 	LIST_INIT(&evo->buffer.callbacks);
-	evo->buffer.refcnt = 1; 
-	evo->buffer.last_with_datap = &evo->buffer.first; 
- 
-	evo->buffer.is_overlapped = 1; 
-	evo->fd = fd; 
- 
-	return &evo->buffer; 
-} 
- 
-int 
+	evo->buffer.refcnt = 1;
+	evo->buffer.last_with_datap = &evo->buffer.first;
+
+	evo->buffer.is_overlapped = 1;
+	evo->fd = fd;
+
+	return &evo->buffer;
+}
+
+int
 evbuffer_launch_write_(struct evbuffer *buf, ev_ssize_t at_most,
-		struct event_overlapped *ol) 
-{ 
-	struct evbuffer_overlapped *buf_o = upcast_evbuffer(buf); 
-	int r = -1; 
-	int i; 
-	struct evbuffer_chain *chain; 
-	DWORD bytesSent; 
- 
-	if (!buf) { 
-		/* No buffer, or it isn't overlapped */ 
-		return -1; 
-	} 
- 
-	EVBUFFER_LOCK(buf); 
-	EVUTIL_ASSERT(!buf_o->read_in_progress); 
-	if (buf->freeze_start || buf_o->write_in_progress) 
-		goto done; 
-	if (!buf->total_len) { 
-		/* Nothing to write */ 
-		r = 0; 
-		goto done; 
-	} else if (at_most < 0 || (size_t)at_most > buf->total_len) { 
-		at_most = buf->total_len; 
-	} 
-	evbuffer_freeze(buf, 1); 
- 
-	buf_o->first_pinned = NULL; 
-	buf_o->n_buffers = 0; 
-	memset(buf_o->buffers, 0, sizeof(buf_o->buffers)); 
- 
-	chain = buf_o->first_pinned = buf->first; 
- 
-	for (i=0; i < MAX_WSABUFS && chain; ++i, chain=chain->next) { 
-		WSABUF *b = &buf_o->buffers[i]; 
-		b->buf = (char*)( chain->buffer + chain->misalign ); 
+		struct event_overlapped *ol)
+{
+	struct evbuffer_overlapped *buf_o = upcast_evbuffer(buf);
+	int r = -1;
+	int i;
+	struct evbuffer_chain *chain;
+	DWORD bytesSent;
+
+	if (!buf) {
+		/* No buffer, or it isn't overlapped */
+		return -1;
+	}
+
+	EVBUFFER_LOCK(buf);
+	EVUTIL_ASSERT(!buf_o->read_in_progress);
+	if (buf->freeze_start || buf_o->write_in_progress)
+		goto done;
+	if (!buf->total_len) {
+		/* Nothing to write */
+		r = 0;
+		goto done;
+	} else if (at_most < 0 || (size_t)at_most > buf->total_len) {
+		at_most = buf->total_len;
+	}
+	evbuffer_freeze(buf, 1);
+
+	buf_o->first_pinned = NULL;
+	buf_o->n_buffers = 0;
+	memset(buf_o->buffers, 0, sizeof(buf_o->buffers));
+
+	chain = buf_o->first_pinned = buf->first;
+
+	for (i=0; i < MAX_WSABUFS && chain; ++i, chain=chain->next) {
+		WSABUF *b = &buf_o->buffers[i];
+		b->buf = (char*)( chain->buffer + chain->misalign );
 		evbuffer_chain_pin_(chain, EVBUFFER_MEM_PINNED_W);
- 
-		if ((size_t)at_most > chain->off) { 
-			/* XXXX Cast is safe for now, since win32 has no 
-			   mmaped chains.  But later, we need to have this 
-			   add more WSAbufs if chain->off is greater than 
-			   ULONG_MAX */ 
-			b->len = (unsigned long)chain->off; 
-			at_most -= chain->off; 
-		} else { 
-			b->len = (unsigned long)at_most; 
-			++i; 
-			break; 
-		} 
-	} 
- 
-	buf_o->n_buffers = i; 
+
+		if ((size_t)at_most > chain->off) {
+			/* XXXX Cast is safe for now, since win32 has no
+			   mmaped chains.  But later, we need to have this
+			   add more WSAbufs if chain->off is greater than
+			   ULONG_MAX */
+			b->len = (unsigned long)chain->off;
+			at_most -= chain->off;
+		} else {
+			b->len = (unsigned long)at_most;
+			++i;
+			break;
+		}
+	}
+
+	buf_o->n_buffers = i;
 	evbuffer_incref_(buf);
-	if (WSASend(buf_o->fd, buf_o->buffers, i, &bytesSent, 0, 
-		&ol->overlapped, NULL)) { 
-		int error = WSAGetLastError(); 
-		if (error != WSA_IO_PENDING) { 
-			/* An actual error. */ 
-			pin_release(buf_o, EVBUFFER_MEM_PINNED_W); 
-			evbuffer_unfreeze(buf, 1); 
-			evbuffer_free(buf); /* decref */ 
-			goto done; 
-		} 
-	} 
- 
-	buf_o->write_in_progress = 1; 
-	r = 0; 
-done: 
-	EVBUFFER_UNLOCK(buf); 
-	return r; 
-} 
- 
-int 
+	if (WSASend(buf_o->fd, buf_o->buffers, i, &bytesSent, 0,
+		&ol->overlapped, NULL)) {
+		int error = WSAGetLastError();
+		if (error != WSA_IO_PENDING) {
+			/* An actual error. */
+			pin_release(buf_o, EVBUFFER_MEM_PINNED_W);
+			evbuffer_unfreeze(buf, 1);
+			evbuffer_free(buf); /* decref */
+			goto done;
+		}
+	}
+
+	buf_o->write_in_progress = 1;
+	r = 0;
+done:
+	EVBUFFER_UNLOCK(buf);
+	return r;
+}
+
+int
 evbuffer_launch_read_(struct evbuffer *buf, size_t at_most,
-		struct event_overlapped *ol) 
-{ 
-	struct evbuffer_overlapped *buf_o = upcast_evbuffer(buf); 
-	int r = -1, i; 
-	int nvecs; 
-	int npin=0; 
-	struct evbuffer_chain *chain=NULL, **chainp; 
-	DWORD bytesRead; 
-	DWORD flags = 0; 
-	struct evbuffer_iovec vecs[MAX_WSABUFS]; 
- 
-	if (!buf_o) 
-		return -1; 
-	EVBUFFER_LOCK(buf); 
-	EVUTIL_ASSERT(!buf_o->write_in_progress); 
-	if (buf->freeze_end || buf_o->read_in_progress) 
-		goto done; 
- 
-	buf_o->first_pinned = NULL; 
-	buf_o->n_buffers = 0; 
-	memset(buf_o->buffers, 0, sizeof(buf_o->buffers)); 
- 
+		struct event_overlapped *ol)
+{
+	struct evbuffer_overlapped *buf_o = upcast_evbuffer(buf);
+	int r = -1, i;
+	int nvecs;
+	int npin=0;
+	struct evbuffer_chain *chain=NULL, **chainp;
+	DWORD bytesRead;
+	DWORD flags = 0;
+	struct evbuffer_iovec vecs[MAX_WSABUFS];
+
+	if (!buf_o)
+		return -1;
+	EVBUFFER_LOCK(buf);
+	EVUTIL_ASSERT(!buf_o->write_in_progress);
+	if (buf->freeze_end || buf_o->read_in_progress)
+		goto done;
+
+	buf_o->first_pinned = NULL;
+	buf_o->n_buffers = 0;
+	memset(buf_o->buffers, 0, sizeof(buf_o->buffers));
+
 	if (evbuffer_expand_fast_(buf, at_most, MAX_WSABUFS) == -1)
-		goto done; 
-	evbuffer_freeze(buf, 0); 
- 
+		goto done;
+	evbuffer_freeze(buf, 0);
+
 	nvecs = evbuffer_read_setup_vecs_(buf, at_most,
-	    vecs, MAX_WSABUFS, &chainp, 1); 
-	for (i=0;i<nvecs;++i) { 
-		WSABUF_FROM_EVBUFFER_IOV( 
-			&buf_o->buffers[i], 
-			&vecs[i]); 
-	} 
- 
-	buf_o->n_buffers = nvecs; 
-	buf_o->first_pinned = chain = *chainp; 
- 
-	npin=0; 
-	for ( ; chain; chain = chain->next) { 
+	    vecs, MAX_WSABUFS, &chainp, 1);
+	for (i=0;i<nvecs;++i) {
+		WSABUF_FROM_EVBUFFER_IOV(
+			&buf_o->buffers[i],
+			&vecs[i]);
+	}
+
+	buf_o->n_buffers = nvecs;
+	buf_o->first_pinned = chain = *chainp;
+
+	npin=0;
+	for ( ; chain; chain = chain->next) {
 		evbuffer_chain_pin_(chain, EVBUFFER_MEM_PINNED_R);
-		++npin; 
-	} 
-	EVUTIL_ASSERT(npin == nvecs); 
- 
+		++npin;
+	}
+	EVUTIL_ASSERT(npin == nvecs);
+
 	evbuffer_incref_(buf);
-	if (WSARecv(buf_o->fd, buf_o->buffers, nvecs, &bytesRead, &flags, 
-		    &ol->overlapped, NULL)) { 
-		int error = WSAGetLastError(); 
-		if (error != WSA_IO_PENDING) { 
-			/* An actual error. */ 
-			pin_release(buf_o, EVBUFFER_MEM_PINNED_R); 
-			evbuffer_unfreeze(buf, 0); 
-			evbuffer_free(buf); /* decref */ 
-			goto done; 
-		} 
-	} 
- 
-	buf_o->read_in_progress = 1; 
-	r = 0; 
-done: 
-	EVBUFFER_UNLOCK(buf); 
-	return r; 
-} 
- 
-evutil_socket_t 
+	if (WSARecv(buf_o->fd, buf_o->buffers, nvecs, &bytesRead, &flags,
+		    &ol->overlapped, NULL)) {
+		int error = WSAGetLastError();
+		if (error != WSA_IO_PENDING) {
+			/* An actual error. */
+			pin_release(buf_o, EVBUFFER_MEM_PINNED_R);
+			evbuffer_unfreeze(buf, 0);
+			evbuffer_free(buf); /* decref */
+			goto done;
+		}
+	}
+
+	buf_o->read_in_progress = 1;
+	r = 0;
+done:
+	EVBUFFER_UNLOCK(buf);
+	return r;
+}
+
+evutil_socket_t
 evbuffer_overlapped_get_fd_(struct evbuffer *buf)
-{ 
-	struct evbuffer_overlapped *buf_o = upcast_evbuffer(buf); 
-	return buf_o ? buf_o->fd : -1; 
-} 
- 
-void 
+{
+	struct evbuffer_overlapped *buf_o = upcast_evbuffer(buf);
+	return buf_o ? buf_o->fd : -1;
+}
+
+void
 evbuffer_overlapped_set_fd_(struct evbuffer *buf, evutil_socket_t fd)
-{ 
-	struct evbuffer_overlapped *buf_o = upcast_evbuffer(buf); 
-	EVBUFFER_LOCK(buf); 
-	/* XXX is this right?, should it cancel current I/O operations? */ 
-	if (buf_o) 
-		buf_o->fd = fd; 
-	EVBUFFER_UNLOCK(buf); 
-} 
+{
+	struct evbuffer_overlapped *buf_o = upcast_evbuffer(buf);
+	EVBUFFER_LOCK(buf);
+	/* XXX is this right?, should it cancel current I/O operations? */
+	if (buf_o)
+		buf_o->fd = fd;
+	EVBUFFER_UNLOCK(buf);
+}

+ 367 - 367
contrib/libs/libevent/bufferevent-internal.h

@@ -1,45 +1,45 @@
-/* 
- * Copyright (c) 2008-2012 Niels Provos and Nick Mathewson 
- * 
- * Redistribution and use in source and binary forms, with or without 
- * modification, are permitted provided that the following conditions 
- * are met: 
- * 1. Redistributions of source code must retain the above copyright 
- *    notice, this list of conditions and the following disclaimer. 
- * 2. Redistributions in binary form must reproduce the above copyright 
- *    notice, this list of conditions and the following disclaimer in the 
- *    documentation and/or other materials provided with the distribution. 
- * 3. The name of the author may not be used to endorse or promote products 
- *    derived from this software without specific prior written permission. 
- * 
- * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 
- * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 
- * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 
- * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 
- * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 
- * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 
- * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 
- * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 
- * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 
- * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 
- */ 
+/*
+ * Copyright (c) 2008-2012 Niels Provos and Nick Mathewson
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ * 3. The name of the author may not be used to endorse or promote products
+ *    derived from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
+ * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+ * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+ * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
+ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
 #ifndef BUFFEREVENT_INTERNAL_H_INCLUDED_
 #define BUFFEREVENT_INTERNAL_H_INCLUDED_
- 
-#ifdef __cplusplus 
-extern "C" { 
-#endif 
- 
-#include "event2/event-config.h" 
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+#include "event2/event-config.h"
 #include "event2/event_struct.h"
 #include "evconfig-private.h"
-#include "event2/util.h" 
-#include "defer-internal.h" 
-#include "evthread-internal.h" 
-#include "event2/thread.h" 
-#include "ratelim-internal.h" 
-#include "event2/bufferevent_struct.h" 
- 
+#include "event2/util.h"
+#include "defer-internal.h"
+#include "evthread-internal.h"
+#include "event2/thread.h"
+#include "ratelim-internal.h"
+#include "event2/bufferevent_struct.h"
+
 #include "ipv6-internal.h"
 #ifdef _WIN32
 #include <ws2tcpip.h>
@@ -51,161 +51,161 @@ extern "C" {
 #error #include <netinet/in6.h>
 #endif
 
-/* These flags are reasons that we might be declining to actually enable 
-   reading or writing on a bufferevent. 
- */ 
- 
-/* On a all bufferevents, for reading: used when we have read up to the 
-   watermark value. 
- 
-   On a filtering bufferevent, for writing: used when the underlying 
-   bufferevent's write buffer has been filled up to its watermark 
-   value. 
-*/ 
-#define BEV_SUSPEND_WM 0x01 
-/* On a base bufferevent: when we have emptied a bandwidth buckets */ 
-#define BEV_SUSPEND_BW 0x02 
-/* On a base bufferevent: when we have emptied the group's bandwidth bucket. */ 
-#define BEV_SUSPEND_BW_GROUP 0x04 
-/* On a socket bufferevent: can't do any operations while we're waiting for 
- * name lookup to finish. */ 
-#define BEV_SUSPEND_LOOKUP 0x08 
-/* On a base bufferevent, for reading: used when a filter has choked this 
- * (underlying) bufferevent because it has stopped reading from it. */ 
-#define BEV_SUSPEND_FILT_READ 0x10 
- 
-typedef ev_uint16_t bufferevent_suspend_flags; 
- 
-struct bufferevent_rate_limit_group { 
-	/** List of all members in the group */ 
+/* These flags are reasons that we might be declining to actually enable
+   reading or writing on a bufferevent.
+ */
+
+/* On a all bufferevents, for reading: used when we have read up to the
+   watermark value.
+
+   On a filtering bufferevent, for writing: used when the underlying
+   bufferevent's write buffer has been filled up to its watermark
+   value.
+*/
+#define BEV_SUSPEND_WM 0x01
+/* On a base bufferevent: when we have emptied a bandwidth buckets */
+#define BEV_SUSPEND_BW 0x02
+/* On a base bufferevent: when we have emptied the group's bandwidth bucket. */
+#define BEV_SUSPEND_BW_GROUP 0x04
+/* On a socket bufferevent: can't do any operations while we're waiting for
+ * name lookup to finish. */
+#define BEV_SUSPEND_LOOKUP 0x08
+/* On a base bufferevent, for reading: used when a filter has choked this
+ * (underlying) bufferevent because it has stopped reading from it. */
+#define BEV_SUSPEND_FILT_READ 0x10
+
+typedef ev_uint16_t bufferevent_suspend_flags;
+
+struct bufferevent_rate_limit_group {
+	/** List of all members in the group */
 	LIST_HEAD(rlim_group_member_list, bufferevent_private) members;
-	/** Current limits for the group. */ 
-	struct ev_token_bucket rate_limit; 
-	struct ev_token_bucket_cfg rate_limit_cfg; 
- 
-	/** True iff we don't want to read from any member of the group.until 
-	 * the token bucket refills.  */ 
-	unsigned read_suspended : 1; 
-	/** True iff we don't want to write from any member of the group.until 
-	 * the token bucket refills.  */ 
-	unsigned write_suspended : 1; 
-	/** True iff we were unable to suspend one of the bufferevents in the 
-	 * group for reading the last time we tried, and we should try 
-	 * again. */ 
-	unsigned pending_unsuspend_read : 1; 
-	/** True iff we were unable to suspend one of the bufferevents in the 
-	 * group for writing the last time we tried, and we should try 
-	 * again. */ 
-	unsigned pending_unsuspend_write : 1; 
- 
-	/*@{*/ 
-	/** Total number of bytes read or written in this group since last 
-	 * reset. */ 
-	ev_uint64_t total_read; 
-	ev_uint64_t total_written; 
-	/*@}*/ 
- 
-	/** The number of bufferevents in the group. */ 
-	int n_members; 
- 
-	/** The smallest number of bytes that any member of the group should 
-	 * be limited to read or write at a time. */ 
-	ev_ssize_t min_share; 
-	ev_ssize_t configured_min_share; 
- 
-	/** Timeout event that goes off once a tick, when the bucket is ready 
-	 * to refill. */ 
-	struct event master_refill_event; 
+	/** Current limits for the group. */
+	struct ev_token_bucket rate_limit;
+	struct ev_token_bucket_cfg rate_limit_cfg;
+
+	/** True iff we don't want to read from any member of the group.until
+	 * the token bucket refills.  */
+	unsigned read_suspended : 1;
+	/** True iff we don't want to write from any member of the group.until
+	 * the token bucket refills.  */
+	unsigned write_suspended : 1;
+	/** True iff we were unable to suspend one of the bufferevents in the
+	 * group for reading the last time we tried, and we should try
+	 * again. */
+	unsigned pending_unsuspend_read : 1;
+	/** True iff we were unable to suspend one of the bufferevents in the
+	 * group for writing the last time we tried, and we should try
+	 * again. */
+	unsigned pending_unsuspend_write : 1;
+
+	/*@{*/
+	/** Total number of bytes read or written in this group since last
+	 * reset. */
+	ev_uint64_t total_read;
+	ev_uint64_t total_written;
+	/*@}*/
+
+	/** The number of bufferevents in the group. */
+	int n_members;
+
+	/** The smallest number of bytes that any member of the group should
+	 * be limited to read or write at a time. */
+	ev_ssize_t min_share;
+	ev_ssize_t configured_min_share;
+
+	/** Timeout event that goes off once a tick, when the bucket is ready
+	 * to refill. */
+	struct event master_refill_event;
 
 	/** Seed for weak random number generator. Protected by 'lock' */
 	struct evutil_weakrand_state weakrand_seed;
 
-	/** Lock to protect the members of this group.  This lock should nest 
-	 * within every bufferevent lock: if you are holding this lock, do 
-	 * not assume you can lock another bufferevent. */ 
-	void *lock; 
-}; 
- 
-/** Fields for rate-limiting a single bufferevent. */ 
-struct bufferevent_rate_limit { 
-	/* Linked-list elements for storing this bufferevent_private in a 
-	 * group. 
-	 * 
-	 * Note that this field is supposed to be protected by the group 
-	 * lock */ 
+	/** Lock to protect the members of this group.  This lock should nest
+	 * within every bufferevent lock: if you are holding this lock, do
+	 * not assume you can lock another bufferevent. */
+	void *lock;
+};
+
+/** Fields for rate-limiting a single bufferevent. */
+struct bufferevent_rate_limit {
+	/* Linked-list elements for storing this bufferevent_private in a
+	 * group.
+	 *
+	 * Note that this field is supposed to be protected by the group
+	 * lock */
 	LIST_ENTRY(bufferevent_private) next_in_group;
-	/** The rate-limiting group for this bufferevent, or NULL if it is 
-	 * only rate-limited on its own. */ 
-	struct bufferevent_rate_limit_group *group; 
- 
-	/* This bufferevent's current limits. */ 
-	struct ev_token_bucket limit; 
-	/* Pointer to the rate-limit configuration for this bufferevent. 
-	 * Can be shared.  XXX reference-count this? */ 
-	struct ev_token_bucket_cfg *cfg; 
- 
-	/* Timeout event used when one this bufferevent's buckets are 
-	 * empty. */ 
-	struct event refill_bucket_event; 
-}; 
- 
-/** Parts of the bufferevent structure that are shared among all bufferevent 
- * types, but not exposed in bufferevent_struct.h. */ 
-struct bufferevent_private { 
-	/** The underlying bufferevent structure. */ 
-	struct bufferevent bev; 
- 
-	/** Evbuffer callback to enforce watermarks on input. */ 
-	struct evbuffer_cb_entry *read_watermarks_cb; 
- 
-	/** If set, we should free the lock when we free the bufferevent. */ 
-	unsigned own_lock : 1; 
- 
-	/** Flag: set if we have deferred callbacks and a read callback is 
-	 * pending. */ 
-	unsigned readcb_pending : 1; 
-	/** Flag: set if we have deferred callbacks and a write callback is 
-	 * pending. */ 
-	unsigned writecb_pending : 1; 
-	/** Flag: set if we are currently busy connecting. */ 
-	unsigned connecting : 1; 
-	/** Flag: set if a connect failed prematurely; this is a hack for 
-	 * getting around the bufferevent abstraction. */ 
-	unsigned connection_refused : 1; 
-	/** Set to the events pending if we have deferred callbacks and 
-	 * an events callback is pending. */ 
-	short eventcb_pending; 
- 
-	/** If set, read is suspended until one or more conditions are over. 
-	 * The actual value here is a bitfield of those conditions; see the 
-	 * BEV_SUSPEND_* flags above. */ 
-	bufferevent_suspend_flags read_suspended; 
- 
-	/** If set, writing is suspended until one or more conditions are over. 
-	 * The actual value here is a bitfield of those conditions; see the 
-	 * BEV_SUSPEND_* flags above. */ 
-	bufferevent_suspend_flags write_suspended; 
- 
-	/** Set to the current socket errno if we have deferred callbacks and 
-	 * an events callback is pending. */ 
-	int errno_pending; 
- 
-	/** The DNS error code for bufferevent_socket_connect_hostname */ 
-	int dns_error; 
- 
-	/** Used to implement deferred callbacks */ 
+	/** The rate-limiting group for this bufferevent, or NULL if it is
+	 * only rate-limited on its own. */
+	struct bufferevent_rate_limit_group *group;
+
+	/* This bufferevent's current limits. */
+	struct ev_token_bucket limit;
+	/* Pointer to the rate-limit configuration for this bufferevent.
+	 * Can be shared.  XXX reference-count this? */
+	struct ev_token_bucket_cfg *cfg;
+
+	/* Timeout event used when one this bufferevent's buckets are
+	 * empty. */
+	struct event refill_bucket_event;
+};
+
+/** Parts of the bufferevent structure that are shared among all bufferevent
+ * types, but not exposed in bufferevent_struct.h. */
+struct bufferevent_private {
+	/** The underlying bufferevent structure. */
+	struct bufferevent bev;
+
+	/** Evbuffer callback to enforce watermarks on input. */
+	struct evbuffer_cb_entry *read_watermarks_cb;
+
+	/** If set, we should free the lock when we free the bufferevent. */
+	unsigned own_lock : 1;
+
+	/** Flag: set if we have deferred callbacks and a read callback is
+	 * pending. */
+	unsigned readcb_pending : 1;
+	/** Flag: set if we have deferred callbacks and a write callback is
+	 * pending. */
+	unsigned writecb_pending : 1;
+	/** Flag: set if we are currently busy connecting. */
+	unsigned connecting : 1;
+	/** Flag: set if a connect failed prematurely; this is a hack for
+	 * getting around the bufferevent abstraction. */
+	unsigned connection_refused : 1;
+	/** Set to the events pending if we have deferred callbacks and
+	 * an events callback is pending. */
+	short eventcb_pending;
+
+	/** If set, read is suspended until one or more conditions are over.
+	 * The actual value here is a bitfield of those conditions; see the
+	 * BEV_SUSPEND_* flags above. */
+	bufferevent_suspend_flags read_suspended;
+
+	/** If set, writing is suspended until one or more conditions are over.
+	 * The actual value here is a bitfield of those conditions; see the
+	 * BEV_SUSPEND_* flags above. */
+	bufferevent_suspend_flags write_suspended;
+
+	/** Set to the current socket errno if we have deferred callbacks and
+	 * an events callback is pending. */
+	int errno_pending;
+
+	/** The DNS error code for bufferevent_socket_connect_hostname */
+	int dns_error;
+
+	/** Used to implement deferred callbacks */
 	struct event_callback deferred;
- 
-	/** The options this bufferevent was constructed with */ 
-	enum bufferevent_options options; 
- 
-	/** Current reference count for this bufferevent. */ 
-	int refcnt; 
- 
-	/** Lock for this bufferevent.  Shared by the inbuf and the outbuf. 
-	 * If NULL, locking is disabled. */ 
-	void *lock; 
- 
+
+	/** The options this bufferevent was constructed with */
+	enum bufferevent_options options;
+
+	/** Current reference count for this bufferevent. */
+	int refcnt;
+
+	/** Lock for this bufferevent.  Shared by the inbuf and the outbuf.
+	 * If NULL, locking is disabled. */
+	void *lock;
+
 	/** No matter how big our bucket gets, don't try to read more than this
 	 * much in a single read operation. */
 	ev_ssize_t max_single_read;
@@ -214,8 +214,8 @@ struct bufferevent_private {
 	 * much in a single write operation. */
 	ev_ssize_t max_single_write;
 
-	/** Rate-limiting information for this bufferevent */ 
-	struct bufferevent_rate_limit *rate_limiting; 
+	/** Rate-limiting information for this bufferevent */
+	struct bufferevent_rate_limit *rate_limiting;
 
 	/* Saved conn_addr, to extract IP address from it.
 	 *
@@ -230,82 +230,82 @@ struct bufferevent_private {
 	} conn_address;
 
 	struct evdns_getaddrinfo_request *dns_request;
-}; 
- 
-/** Possible operations for a control callback. */ 
-enum bufferevent_ctrl_op { 
-	BEV_CTRL_SET_FD, 
-	BEV_CTRL_GET_FD, 
-	BEV_CTRL_GET_UNDERLYING, 
-	BEV_CTRL_CANCEL_ALL 
-}; 
- 
-/** Possible data types for a control callback */ 
-union bufferevent_ctrl_data { 
-	void *ptr; 
-	evutil_socket_t fd; 
-}; 
- 
-/** 
-   Implementation table for a bufferevent: holds function pointers and other 
-   information to make the various bufferevent types work. 
-*/ 
-struct bufferevent_ops { 
-	/** The name of the bufferevent's type. */ 
-	const char *type; 
-	/** At what offset into the implementation type will we find a 
-	    bufferevent structure? 
- 
-	    Example: if the type is implemented as 
-	    struct bufferevent_x { 
-	       int extra_data; 
-	       struct bufferevent bev; 
-	    } 
-	    then mem_offset should be offsetof(struct bufferevent_x, bev) 
-	*/ 
-	off_t mem_offset; 
- 
-	/** Enables one or more of EV_READ|EV_WRITE on a bufferevent.  Does 
-	    not need to adjust the 'enabled' field.  Returns 0 on success, -1 
-	    on failure. 
-	 */ 
-	int (*enable)(struct bufferevent *, short); 
- 
-	/** Disables one or more of EV_READ|EV_WRITE on a bufferevent.  Does 
-	    not need to adjust the 'enabled' field.  Returns 0 on success, -1 
-	    on failure. 
-	 */ 
-	int (*disable)(struct bufferevent *, short); 
- 
+};
+
+/** Possible operations for a control callback. */
+enum bufferevent_ctrl_op {
+	BEV_CTRL_SET_FD,
+	BEV_CTRL_GET_FD,
+	BEV_CTRL_GET_UNDERLYING,
+	BEV_CTRL_CANCEL_ALL
+};
+
+/** Possible data types for a control callback */
+union bufferevent_ctrl_data {
+	void *ptr;
+	evutil_socket_t fd;
+};
+
+/**
+   Implementation table for a bufferevent: holds function pointers and other
+   information to make the various bufferevent types work.
+*/
+struct bufferevent_ops {
+	/** The name of the bufferevent's type. */
+	const char *type;
+	/** At what offset into the implementation type will we find a
+	    bufferevent structure?
+
+	    Example: if the type is implemented as
+	    struct bufferevent_x {
+	       int extra_data;
+	       struct bufferevent bev;
+	    }
+	    then mem_offset should be offsetof(struct bufferevent_x, bev)
+	*/
+	off_t mem_offset;
+
+	/** Enables one or more of EV_READ|EV_WRITE on a bufferevent.  Does
+	    not need to adjust the 'enabled' field.  Returns 0 on success, -1
+	    on failure.
+	 */
+	int (*enable)(struct bufferevent *, short);
+
+	/** Disables one or more of EV_READ|EV_WRITE on a bufferevent.  Does
+	    not need to adjust the 'enabled' field.  Returns 0 on success, -1
+	    on failure.
+	 */
+	int (*disable)(struct bufferevent *, short);
+
 	/** Detatches the bufferevent from related data structures. Called as
 	 * soon as its reference count reaches 0. */
 	void (*unlink)(struct bufferevent *);
 
-	/** Free any storage and deallocate any extra data or structures used 
+	/** Free any storage and deallocate any extra data or structures used
 	    in this implementation. Called when the bufferevent is
 	    finalized.
-	 */ 
-	void (*destruct)(struct bufferevent *); 
- 
-	/** Called when the timeouts on the bufferevent have changed.*/ 
-	int (*adj_timeouts)(struct bufferevent *); 
- 
-	/** Called to flush data. */ 
-	int (*flush)(struct bufferevent *, short, enum bufferevent_flush_mode); 
- 
-	/** Called to access miscellaneous fields. */ 
-	int (*ctrl)(struct bufferevent *, enum bufferevent_ctrl_op, union bufferevent_ctrl_data *); 
- 
-}; 
- 
-extern const struct bufferevent_ops bufferevent_ops_socket; 
-extern const struct bufferevent_ops bufferevent_ops_filter; 
-extern const struct bufferevent_ops bufferevent_ops_pair; 
- 
-#define BEV_IS_SOCKET(bevp) ((bevp)->be_ops == &bufferevent_ops_socket) 
-#define BEV_IS_FILTER(bevp) ((bevp)->be_ops == &bufferevent_ops_filter) 
-#define BEV_IS_PAIR(bevp) ((bevp)->be_ops == &bufferevent_ops_pair) 
- 
+	 */
+	void (*destruct)(struct bufferevent *);
+
+	/** Called when the timeouts on the bufferevent have changed.*/
+	int (*adj_timeouts)(struct bufferevent *);
+
+	/** Called to flush data. */
+	int (*flush)(struct bufferevent *, short, enum bufferevent_flush_mode);
+
+	/** Called to access miscellaneous fields. */
+	int (*ctrl)(struct bufferevent *, enum bufferevent_ctrl_op, union bufferevent_ctrl_data *);
+
+};
+
+extern const struct bufferevent_ops bufferevent_ops_socket;
+extern const struct bufferevent_ops bufferevent_ops_filter;
+extern const struct bufferevent_ops bufferevent_ops_pair;
+
+#define BEV_IS_SOCKET(bevp) ((bevp)->be_ops == &bufferevent_ops_socket)
+#define BEV_IS_FILTER(bevp) ((bevp)->be_ops == &bufferevent_ops_filter)
+#define BEV_IS_PAIR(bevp) ((bevp)->be_ops == &bufferevent_ops_pair)
+
 #if defined(EVENT__HAVE_OPENSSL)
 extern const struct bufferevent_ops bufferevent_ops_openssl;
 #define BEV_IS_OPENSSL(bevp) ((bevp)->be_ops == &bufferevent_ops_openssl)
@@ -314,87 +314,87 @@ extern const struct bufferevent_ops bufferevent_ops_openssl;
 #endif
 
 #ifdef _WIN32
-extern const struct bufferevent_ops bufferevent_ops_async; 
-#define BEV_IS_ASYNC(bevp) ((bevp)->be_ops == &bufferevent_ops_async) 
-#else 
-#define BEV_IS_ASYNC(bevp) 0 
-#endif 
- 
-/** Initialize the shared parts of a bufferevent. */ 
+extern const struct bufferevent_ops bufferevent_ops_async;
+#define BEV_IS_ASYNC(bevp) ((bevp)->be_ops == &bufferevent_ops_async)
+#else
+#define BEV_IS_ASYNC(bevp) 0
+#endif
+
+/** Initialize the shared parts of a bufferevent. */
 EVENT2_EXPORT_SYMBOL
 int bufferevent_init_common_(struct bufferevent_private *, struct event_base *, const struct bufferevent_ops *, enum bufferevent_options options);
- 
-/** For internal use: temporarily stop all reads on bufev, until the conditions 
- * in 'what' are over. */ 
+
+/** For internal use: temporarily stop all reads on bufev, until the conditions
+ * in 'what' are over. */
 EVENT2_EXPORT_SYMBOL
 void bufferevent_suspend_read_(struct bufferevent *bufev, bufferevent_suspend_flags what);
-/** For internal use: clear the conditions 'what' on bufev, and re-enable 
- * reading if there are no conditions left. */ 
+/** For internal use: clear the conditions 'what' on bufev, and re-enable
+ * reading if there are no conditions left. */
 EVENT2_EXPORT_SYMBOL
 void bufferevent_unsuspend_read_(struct bufferevent *bufev, bufferevent_suspend_flags what);
- 
-/** For internal use: temporarily stop all writes on bufev, until the conditions 
- * in 'what' are over. */ 
+
+/** For internal use: temporarily stop all writes on bufev, until the conditions
+ * in 'what' are over. */
 void bufferevent_suspend_write_(struct bufferevent *bufev, bufferevent_suspend_flags what);
-/** For internal use: clear the conditions 'what' on bufev, and re-enable 
- * writing if there are no conditions left. */ 
+/** For internal use: clear the conditions 'what' on bufev, and re-enable
+ * writing if there are no conditions left. */
 void bufferevent_unsuspend_write_(struct bufferevent *bufev, bufferevent_suspend_flags what);
- 
-#define bufferevent_wm_suspend_read(b) \ 
+
+#define bufferevent_wm_suspend_read(b) \
 	bufferevent_suspend_read_((b), BEV_SUSPEND_WM)
-#define bufferevent_wm_unsuspend_read(b) \ 
+#define bufferevent_wm_unsuspend_read(b) \
 	bufferevent_unsuspend_read_((b), BEV_SUSPEND_WM)
- 
-/* 
-  Disable a bufferevent.  Equivalent to bufferevent_disable(), but 
-  first resets 'connecting' flag to force EV_WRITE down for sure. 
- 
-  XXXX this method will go away in the future; try not to add new users. 
+
+/*
+  Disable a bufferevent.  Equivalent to bufferevent_disable(), but
+  first resets 'connecting' flag to force EV_WRITE down for sure.
+
+  XXXX this method will go away in the future; try not to add new users.
     See comment in evhttp_connection_reset_() for discussion.
- 
-  @param bufev the bufferevent to be disabled 
-  @param event any combination of EV_READ | EV_WRITE. 
-  @return 0 if successful, or -1 if an error occurred 
-  @see bufferevent_disable() 
- */ 
+
+  @param bufev the bufferevent to be disabled
+  @param event any combination of EV_READ | EV_WRITE.
+  @return 0 if successful, or -1 if an error occurred
+  @see bufferevent_disable()
+ */
 EVENT2_EXPORT_SYMBOL
 int bufferevent_disable_hard_(struct bufferevent *bufev, short event);
- 
-/** Internal: Set up locking on a bufferevent.  If lock is set, use it. 
- * Otherwise, use a new lock. */ 
+
+/** Internal: Set up locking on a bufferevent.  If lock is set, use it.
+ * Otherwise, use a new lock. */
 EVENT2_EXPORT_SYMBOL
 int bufferevent_enable_locking_(struct bufferevent *bufev, void *lock);
 /** Internal: backwards compat macro for the now public function
  * Increment the reference count on bufev. */
 #define bufferevent_incref_(bufev) bufferevent_incref(bufev)
-/** Internal: Lock bufev and increase its reference count. 
- * unlocking it otherwise. */ 
+/** Internal: Lock bufev and increase its reference count.
+ * unlocking it otherwise. */
 EVENT2_EXPORT_SYMBOL
 void bufferevent_incref_and_lock_(struct bufferevent *bufev);
 /** Internal: backwards compat macro for the now public function
  * Decrement the reference count on bufev.  Returns 1 if it freed
- * the bufferevent.*/ 
+ * the bufferevent.*/
 #define bufferevent_decref_(bufev) bufferevent_decref(bufev)
 
-/** Internal: Drop the reference count on bufev, freeing as necessary, and 
- * unlocking it otherwise.  Returns 1 if it freed the bufferevent. */ 
+/** Internal: Drop the reference count on bufev, freeing as necessary, and
+ * unlocking it otherwise.  Returns 1 if it freed the bufferevent. */
 EVENT2_EXPORT_SYMBOL
 int bufferevent_decref_and_unlock_(struct bufferevent *bufev);
- 
-/** Internal: If callbacks are deferred and we have a read callback, schedule 
+
+/** Internal: If callbacks are deferred and we have a read callback, schedule
  * a readcb.  Otherwise just run the readcb. Ignores watermarks. */
 EVENT2_EXPORT_SYMBOL
 void bufferevent_run_readcb_(struct bufferevent *bufev, int options);
-/** Internal: If callbacks are deferred and we have a write callback, schedule 
+/** Internal: If callbacks are deferred and we have a write callback, schedule
  * a writecb.  Otherwise just run the writecb. Ignores watermarks. */
 EVENT2_EXPORT_SYMBOL
 void bufferevent_run_writecb_(struct bufferevent *bufev, int options);
-/** Internal: If callbacks are deferred and we have an eventcb, schedule 
+/** Internal: If callbacks are deferred and we have an eventcb, schedule
  * it to run with events "what".  Otherwise just run the eventcb.
  * See bufferevent_trigger_event for meaning of "options". */
 EVENT2_EXPORT_SYMBOL
 void bufferevent_run_eventcb_(struct bufferevent *bufev, short what, int options);
- 
+
 /** Internal: Run or schedule (if deferred or options contain
  * BEV_TRIG_DEFER_CALLBACKS) I/O callbacks specified in iotype.
  * Must already hold the bufev lock. Honors watermarks unless
@@ -414,29 +414,29 @@ bufferevent_trigger_nolock_(struct bufferevent *bufev, short iotype, int options
 		bufferevent_run_writecb_(bufev, options);
 }
 
-/** Internal: Add the event 'ev' with timeout tv, unless tv is set to 0, in 
- * which case add ev with no timeout. */ 
+/** Internal: Add the event 'ev' with timeout tv, unless tv is set to 0, in
+ * which case add ev with no timeout. */
 EVENT2_EXPORT_SYMBOL
 int bufferevent_add_event_(struct event *ev, const struct timeval *tv);
- 
-/* ========= 
- * These next functions implement timeouts for bufferevents that aren't doing 
- * anything else with ev_read and ev_write, to handle timeouts. 
- * ========= */ 
-/** Internal use: Set up the ev_read and ev_write callbacks so that 
- * the other "generic_timeout" functions will work on it.  Call this from 
- * the constructor function. */ 
+
+/* =========
+ * These next functions implement timeouts for bufferevents that aren't doing
+ * anything else with ev_read and ev_write, to handle timeouts.
+ * ========= */
+/** Internal use: Set up the ev_read and ev_write callbacks so that
+ * the other "generic_timeout" functions will work on it.  Call this from
+ * the constructor function. */
 EVENT2_EXPORT_SYMBOL
 void bufferevent_init_generic_timeout_cbs_(struct bufferevent *bev);
-/** Internal use: Add or delete the generic timeout events as appropriate. 
- * (If an event is enabled and a timeout is set, we add the event.  Otherwise 
- * we delete it.)  Call this from anything that changes the timeout values, 
- * that enabled EV_READ or EV_WRITE, or that disables EV_READ or EV_WRITE. */ 
+/** Internal use: Add or delete the generic timeout events as appropriate.
+ * (If an event is enabled and a timeout is set, we add the event.  Otherwise
+ * we delete it.)  Call this from anything that changes the timeout values,
+ * that enabled EV_READ or EV_WRITE, or that disables EV_READ or EV_WRITE. */
 EVENT2_EXPORT_SYMBOL
 int bufferevent_generic_adj_timeouts_(struct bufferevent *bev);
 EVENT2_EXPORT_SYMBOL
 int bufferevent_generic_adj_existing_timeouts_(struct bufferevent *bev);
- 
+
 EVENT2_EXPORT_SYMBOL
 enum bufferevent_options bufferevent_get_options_(struct bufferevent *bev);
 
@@ -453,66 +453,66 @@ void
 bufferevent_socket_set_conn_address_(struct bufferevent *bev, struct sockaddr *addr, size_t addrlen);
 
 
-/** Internal use: We have just successfully read data into an inbuf, so 
- * reset the read timeout (if any). */ 
-#define BEV_RESET_GENERIC_READ_TIMEOUT(bev)				\ 
-	do {								\ 
-		if (evutil_timerisset(&(bev)->timeout_read))		\ 
-			event_add(&(bev)->ev_read, &(bev)->timeout_read); \ 
-	} while (0) 
-/** Internal use: We have just successfully written data from an inbuf, so 
- * reset the read timeout (if any). */ 
-#define BEV_RESET_GENERIC_WRITE_TIMEOUT(bev)				\ 
-	do {								\ 
-		if (evutil_timerisset(&(bev)->timeout_write))		\ 
-			event_add(&(bev)->ev_write, &(bev)->timeout_write); \ 
-	} while (0) 
-#define BEV_DEL_GENERIC_READ_TIMEOUT(bev)	\ 
-		event_del(&(bev)->ev_read) 
-#define BEV_DEL_GENERIC_WRITE_TIMEOUT(bev)	\ 
-		event_del(&(bev)->ev_write) 
- 
- 
-/** Internal: Given a bufferevent, return its corresponding 
- * bufferevent_private. */ 
-#define BEV_UPCAST(b) EVUTIL_UPCAST((b), struct bufferevent_private, bev) 
- 
+/** Internal use: We have just successfully read data into an inbuf, so
+ * reset the read timeout (if any). */
+#define BEV_RESET_GENERIC_READ_TIMEOUT(bev)				\
+	do {								\
+		if (evutil_timerisset(&(bev)->timeout_read))		\
+			event_add(&(bev)->ev_read, &(bev)->timeout_read); \
+	} while (0)
+/** Internal use: We have just successfully written data from an inbuf, so
+ * reset the read timeout (if any). */
+#define BEV_RESET_GENERIC_WRITE_TIMEOUT(bev)				\
+	do {								\
+		if (evutil_timerisset(&(bev)->timeout_write))		\
+			event_add(&(bev)->ev_write, &(bev)->timeout_write); \
+	} while (0)
+#define BEV_DEL_GENERIC_READ_TIMEOUT(bev)	\
+		event_del(&(bev)->ev_read)
+#define BEV_DEL_GENERIC_WRITE_TIMEOUT(bev)	\
+		event_del(&(bev)->ev_write)
+
+
+/** Internal: Given a bufferevent, return its corresponding
+ * bufferevent_private. */
+#define BEV_UPCAST(b) EVUTIL_UPCAST((b), struct bufferevent_private, bev)
+
 #ifdef EVENT__DISABLE_THREAD_SUPPORT
 #define BEV_LOCK(b) EVUTIL_NIL_STMT_
 #define BEV_UNLOCK(b) EVUTIL_NIL_STMT_
-#else 
-/** Internal: Grab the lock (if any) on a bufferevent */ 
-#define BEV_LOCK(b) do {						\ 
-		struct bufferevent_private *locking =  BEV_UPCAST(b);	\ 
-		EVLOCK_LOCK(locking->lock, 0);				\ 
-	} while (0) 
- 
-/** Internal: Release the lock (if any) on a bufferevent */ 
-#define BEV_UNLOCK(b) do {						\ 
-		struct bufferevent_private *locking =  BEV_UPCAST(b);	\ 
-		EVLOCK_UNLOCK(locking->lock, 0);			\ 
-	} while (0) 
-#endif 
- 
- 
-/* ==== For rate-limiting. */ 
- 
+#else
+/** Internal: Grab the lock (if any) on a bufferevent */
+#define BEV_LOCK(b) do {						\
+		struct bufferevent_private *locking =  BEV_UPCAST(b);	\
+		EVLOCK_LOCK(locking->lock, 0);				\
+	} while (0)
+
+/** Internal: Release the lock (if any) on a bufferevent */
+#define BEV_UNLOCK(b) do {						\
+		struct bufferevent_private *locking =  BEV_UPCAST(b);	\
+		EVLOCK_UNLOCK(locking->lock, 0);			\
+	} while (0)
+#endif
+
+
+/* ==== For rate-limiting. */
+
 EVENT2_EXPORT_SYMBOL
 int bufferevent_decrement_write_buckets_(struct bufferevent_private *bev,
-    ev_ssize_t bytes); 
+    ev_ssize_t bytes);
 EVENT2_EXPORT_SYMBOL
 int bufferevent_decrement_read_buckets_(struct bufferevent_private *bev,
-    ev_ssize_t bytes); 
+    ev_ssize_t bytes);
 EVENT2_EXPORT_SYMBOL
 ev_ssize_t bufferevent_get_read_max_(struct bufferevent_private *bev);
 EVENT2_EXPORT_SYMBOL
 ev_ssize_t bufferevent_get_write_max_(struct bufferevent_private *bev);
- 
+
 int bufferevent_ratelim_init_(struct bufferevent_private *bev);
 
-#ifdef __cplusplus 
-} 
-#endif 
- 
- 
+#ifdef __cplusplus
+}
+#endif
+
+
 #endif /* BUFFEREVENT_INTERNAL_H_INCLUDED_ */

File diff suppressed because it is too large
+ 481 - 481
contrib/libs/libevent/bufferevent.c


File diff suppressed because it is too large
+ 580 - 580
contrib/libs/libevent/bufferevent_async.c


Some files were not shown because too many files changed in this diff