Skip to content

Commit

Permalink
* Remove unused parameter to item_size_ok()
Browse files Browse the repository at this point in the history
* Use a single printf() in usage()
* Add a failing test for conforming with maximum connections.


git-svn-id: http://code.sixapart.com/svn/memcached/trunk/server@473 b0b603af-a30f-0410-a34e-baf09ae79d0b
  • Loading branch information
lindner committed Mar 19, 2007
1 parent 6ea0fab commit 10862f6
Show file tree
Hide file tree
Showing 6 changed files with 76 additions and 30 deletions.
14 changes: 14 additions & 0 deletions ChangeLog
@@ -1,3 +1,17 @@
2007-03-18 Paul Lindner <lindner@mirth.inuus.com>


2007-03-18 Paul Lindner <lindner@inuus.com>

* Add more test cases using larger buffer sizes up to and greater
than 1MB.

* Remove unused parameter to item_size_ok()

* Use a single printf() in usage()

* Add a failing test for conforming with maximum connections.

2007-03-17
* crash fix from Thomas van Gulick <thomas@partyflock.nl> in
conn_shrink(), passing &ptr, instead of ptr to realloc().
Expand Down
14 changes: 7 additions & 7 deletions items.c
Expand Up @@ -38,8 +38,8 @@ static unsigned int sizes[LARGEST_ID];
void item_init(void) {
int i;
for(i=0; i<LARGEST_ID; i++) {
heads[i]=0;
tails[i]=0;
heads[i]=NULL;
tails[i]=NULL;
sizes[i]=0;
}
}
Expand All @@ -57,7 +57,7 @@ void item_init(void) {
*
* Returns the total size of the header.
*/
static size_t item_make_header(char *key, const uint8_t nkey, const int flags, const int nbytes,
static size_t item_make_header(const uint8_t nkey, const int flags, const int nbytes,
char *suffix, uint8_t *nsuffix) {
/* suffix is defined at 40 chars elsewhere.. */
*nsuffix = (uint8_t) snprintf(suffix, 40, " %d %d\r\n", flags, nbytes - 2);
Expand All @@ -72,7 +72,7 @@ item *item_alloc(char *key, const size_t nkey, const int flags, const rel_time_t
unsigned int id;
char suffix[40];

ntotal = item_make_header(key, nkey + 1, flags, nbytes, suffix, &nsuffix);
ntotal = item_make_header(nkey + 1, flags, nbytes, suffix, &nsuffix);

id = slabs_clsid(ntotal);
if (id == 0)
Expand Down Expand Up @@ -144,11 +144,11 @@ void item_free(item *it) {
* Returns true if an item will fit in the cache (its size does not exceed
* the maximum for a cache entry.)
*/
bool item_size_ok(char *key, const size_t nkey, const int flags, const int nbytes) {
bool item_size_ok(const size_t nkey, const int flags, const int nbytes) {
char prefix[40];
uint8_t nsuffix;

return slabs_clsid(item_make_header(key, nkey + 1, flags, nbytes,
return slabs_clsid(item_make_header(nkey + 1, flags, nbytes,
prefix, &nsuffix)) != 0;
}

Expand Down Expand Up @@ -339,7 +339,7 @@ char* item_stats_sizes(int *bytes) {
}

/* expires items that are more recent than the oldest_live setting. */
void item_flush_expired() {
void item_flush_expired(void) {
int i;
item *iter, *next;
if (settings.oldest_live == 0)
Expand Down
2 changes: 1 addition & 1 deletion items.h
Expand Up @@ -3,7 +3,7 @@ void item_init(void);
/*@null@*/
item *item_alloc(char *key, const size_t nkey, const int flags, const rel_time_t exptime, const int nbytes);
void item_free(item *it);
bool item_size_ok(char *key, const size_t nkey, const int flags, const int nbytes);
bool item_size_ok(const size_t nkey, const int flags, const int nbytes);

int item_link(item *it); /* may fail if transgresses limits */
void item_unlink(item *it);
Expand Down
42 changes: 21 additions & 21 deletions memcached.c
Expand Up @@ -1057,7 +1057,7 @@ static inline void process_get_command(conn *c, token_t* tokens, size_t ntokens)
* of tokens.
*/
if(key_token->value != NULL) {
ntokens = tokenize_command(key_token->value, tokens, MAX_TOKENS);
ntokens = tokenize_command(key_token->value, tokens, MAX_TOKENS);
key_token = tokens;
}

Expand Down Expand Up @@ -1121,7 +1121,7 @@ static void process_update_command(conn *c, token_t* tokens, const size_t ntoken
it = item_alloc(key, nkey, flags, realtime(exptime), vlen+2);

if (it == 0) {
if (! item_size_ok(key, nkey, flags, vlen + 2))
if (! item_size_ok(nkey, flags, vlen + 2))
out_string(c, "SERVER_ERROR object too large for cache");
else
out_string(c, "SERVER_ERROR out of memory");
Expand Down Expand Up @@ -2168,25 +2168,25 @@ static void delete_handler(const int fd, const short which, void *arg) {

static void usage(void) {
printf(PACKAGE " " VERSION "\n");
printf("-p <num> TCP port number to listen on (default: 11211)\n");
printf("-U <num> UDP port number to listen on (default: 0, off)\n");
printf("-s <file> unix socket path to listen on (disables network support)\n");
printf("-l <ip_addr> interface to listen on, default is INDRR_ANY\n");
printf("-d run as a daemon\n");
printf("-r maximize core file limit\n");
printf("-u <username> assume identity of <username> (only when run as root)\n");
printf("-m <num> max memory to use for items in megabytes, default is 64 MB\n");
printf("-M return error on memory exhausted (rather than removing items)\n");
printf("-c <num> max simultaneous connections, default is 1024\n");
printf("-k lock down all paged memory\n");
printf("-v verbose (print errors/warnings while in event loop)\n");
printf("-vv very verbose (also print client commands/reponses)\n");
printf("-h print this help and exit\n");
printf("-i print memcached and libevent license\n");
printf("-b run a managed instanced (mnemonic: buckets)\n");
printf("-P <file> save PID in <file>, only used with -d option\n");
printf("-f <factor> chunk size growth factor, default 1.25\n");
printf("-n <bytes> minimum space allocated for key+value+flags, default 48\n");
printf("-p <num> TCP port number to listen on (default: 11211)\n"
"-U <num> UDP port number to listen on (default: 0, off)\n"
"-s <file> unix socket path to listen on (disables network support)\n"
"-l <ip_addr> interface to listen on, default is INDRR_ANY\n"
"-d run as a daemon\n"
"-r maximize core file limit\n"
"-u <username> assume identity of <username> (only when run as root)\n"
"-m <num> max memory to use for items in megabytes, default is 64 MB\n"
"-M return error on memory exhausted (rather than removing items)\n"
"-c <num> max simultaneous connections, default is 1024\n"
"-k lock down all paged memory\n"
"-v verbose (print errors/warnings while in event loop)\n"
"-vv very verbose (also print client commands/reponses)\n"
"-h print this help and exit\n"
"-i print memcached and libevent license\n"
"-b run a managed instanced (mnemonic: buckets)\n"
"-P <file> save PID in <file>, only used with -d option\n"
"-f <factor> chunk size growth factor, default 1.25\n"
"-n <bytes> minimum space allocated for key+value+flags, default 48\n");
return;
}

Expand Down
2 changes: 1 addition & 1 deletion memcached.h
Expand Up @@ -25,7 +25,7 @@
#if HAVE_STDBOOL_H
# include <stdbool.h>
#else
typedef enum {false = 0, true = 1} bool;
typedef enum {false = 0, true = 1} bool;
#endif

#if HAVE_STDINT_H
Expand Down
32 changes: 32 additions & 0 deletions t/maxconns.t
@@ -0,0 +1,32 @@
#!/usr/bin/perl

use strict;
use warnings;

use Test::More tests => 10;

use FindBin qw($Bin);
use lib "$Bin/lib";
use MemcachedTest;


# start up a server with 10 maximum connections
my $server = new_memcached('-c 10');
my $sock = $server->sock;
my @sockets;

ok(defined($sock), 'Connection 0');
push (@sockets, $sock);

foreach my $conn (1..20) {
$sock = $server->new_sock;
if ($conn > 10) {
ok(!defined($sock), "Failed Connection $conn $sock");
} else {
ok(defined($sock), "Connection $conn");
push(@sockets, $sock);
}
}

mem_stats($sock, '');
sleep(100);

0 comments on commit 10862f6

Please sign in to comment.