1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136
|
/*
dbench version 1
Copyright (C) Andrew Tridgell 1999
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
#include "dbench.h"
#define MAX_FILES 1000
static char buf[70000];
extern int line_count;
char *server = "localhost";
static int sock;
/* emulate a single SMB packet exchange */
static void do_packets(unsigned long send_size, unsigned long recv_size)
{
uint32 *ubuf = (uint32 *)buf;
static int counter;
ubuf[0] = htonl(send_size-4);
ubuf[1] = htonl(recv_size-4);
if (write_sock(sock, buf, send_size) != send_size) {
printf("error writing %d bytes\n", (int)send_size);
exit(1);
}
if (read_sock(sock, buf, 4) != 4) {
printf("error reading header\n");
exit(1);
}
if (ntohl(ubuf[0]) != recv_size-4) {
printf("(%d) lost sync (%d %d)\n",
line_count, (int)recv_size-4, (int)ntohl(ubuf[0]));
exit(1);
}
if (recv(sock, buf, recv_size-4, MSG_WAITALL|MSG_TRUNC) !=
recv_size-4) {
printf("error reading %d bytes\n", (int)recv_size-4);
exit(1);
}
if (ntohl(ubuf[0]) != recv_size-4) {
printf("(%d) lost sync (%d %d)\n",
line_count, (int)recv_size-4, (int)ntohl(ubuf[0]));
}
if (counter++ % 3000 == 0) printf(".");
}
void nb_setup(int client)
{
extern char *tcp_options;
sock = open_socket_out(server, TCP_PORT);
if (sock == -1) {
printf("client %d failed to start\n", client);
exit(1);
}
set_socket_options(sock, tcp_options);
do_packets(8, 8);
}
void nb_unlink(char *fname)
{
do_packets(83, 39);
}
void nb_open(char *fname, int handle, int size)
{
do_packets(111, 69);
}
void nb_write(int handle, int size, int offset)
{
do_packets(51+size, 41);
}
void nb_read(int handle, int size, int offset)
{
do_packets(55, size+4);
}
void nb_close(int handle)
{
do_packets(45, 39);
}
void nb_mkdir(char *fname)
{
do_packets(39+strlen(fname), 39);
}
void nb_rmdir(char *fname)
{
do_packets(39+strlen(fname), 39);
}
void nb_rename(char *old, char *new)
{
do_packets(41+strlen(old)+strlen(new), 39);
}
void nb_stat(char *fname, int size)
{
do_packets(39+strlen(fname), 59);
}
void nb_create(char *fname, int size)
{
nb_open(fname, 5000, size);
nb_close(5000);
}
|