"Fossies" - the Fresh Open Source Software Archive 
Member "httperf-0.9.0/src/lib/ssl_writev.c" (7 Apr 2007, 3316 Bytes) of package /linux/www/old/httperf-0.9.0.tar.gz:
As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) C and C++ source code syntax highlighting (style:
standard) with prefixed line numbers and
code folding option.
Alternatively you can here
view or
download the uninterpreted source code file.
For more information about "ssl_writev.c" see the
Fossies "Dox" file reference documentation.
1 /*
2 httperf -- a tool for measuring web server performance
3 Copyright 2000-2007 Hewlett-Packard Company and Contributors listed in
4 AUTHORS file. Originally contributed by David Mosberger-Tang
5
6 This file is part of httperf, a web server performance measurment
7 tool.
8
9 This program is free software; you can redistribute it and/or
10 modify it under the terms of the GNU General Public License as
11 published by the Free Software Foundation; either version 2 of the
12 License, or (at your option) any later version.
13
14 In addition, as a special exception, the copyright holders give
15 permission to link the code of this work with the OpenSSL project's
16 "OpenSSL" library (or with modified versions of it that use the same
17 license as the "OpenSSL" library), and distribute linked combinations
18 including the two. You must obey the GNU General Public License in
19 all respects for all of the code used other than "OpenSSL". If you
20 modify this file, you may extend this exception to your version of the
21 file, but you are not obligated to do so. If you do not wish to do
22 so, delete this exception statement from your version.
23
24 This program is distributed in the hope that it will be useful,
25 but WITHOUT ANY WARRANTY; without even the implied warranty of
26 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
27 General Public License for more details.
28
29 You should have received a copy of the GNU General Public License
30 along with this program; if not, write to the Free Software
31 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
32 02110-1301, USA
33 */
34
35 /* This code is based on the generic writev() implementation of GNU
36 libc. It implements writev() simply in terms of write(). No
37 atomicity guarantees and performance isn't great either, but its
38 good enough for SSL purposes. */
39
40 #include "config.h"
41
42 #ifdef HAVE_OPENSSL_SSL_H
43
44 /* AIX requires this to be the first thing in the file. */
45 #ifndef __GNUC__
46 # if HAVE_ALLOCA_H
47 # include <alloca.h>
48 # else
49 # ifdef _AIX
50 #pragma alloca
51 # else
52 # ifndef alloca /* predefined by HP cc +Olibcalls */
53 char *alloca ();
54 # endif
55 # endif
56 # endif
57 #else
58 /* stdlib.h provides the alloca functionality. */
59 #include <stdlib.h>
60 #endif
61
62 #include <string.h>
63
64 #include <sys/types.h>
65 #include <sys/uio.h>
66
67 #include <openssl/rsa.h>
68 #include <openssl/crypto.h>
69 #include <openssl/x509.h>
70 #include <openssl/pem.h>
71 #include <openssl/ssl.h>
72 #include <openssl/err.h>
73
74 ssize_t
75 SSL_writev (SSL *ssl, const struct iovec *vector, int count)
76 {
77 char *buffer;
78 register char *bp;
79 size_t bytes, to_copy;
80 int i;
81
82 /* Find the total number of bytes to be written. */
83 bytes = 0;
84 for (i = 0; i < count; ++i)
85 bytes += vector[i].iov_len;
86
87 /* Allocate a temporary buffer to hold the data. */
88 buffer = (char *) alloca (bytes);
89
90 /* Copy the data into BUFFER. */
91 to_copy = bytes;
92 bp = buffer;
93 for (i = 0; i < count; ++i)
94 {
95 # define min(a, b) ((a) > (b) ? (b) : (a))
96 size_t copy = min (vector[i].iov_len, to_copy);
97
98 memcpy ((void *) bp, (void *) vector[i].iov_base, copy);
99 bp += copy;
100
101 to_copy -= copy;
102 if (to_copy == 0)
103 break;
104 }
105
106 return SSL_write (ssl, buffer, bytes);
107 }
108
109 #endif /* HAVE_OPENSSL_SSL_H */