public
Created

testgridfs

  • Download Gist
testgridfs.c
C
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
#include "mongo.h"
#include "gridfs.h"
 
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
 
#include <unistd.h>
#include <sys/types.h>
 
static int count=10000;
 
static int _testgridfs() {
int i, rv;
char data[1024*1024] = {0};
char name[256] = {0};
 
mongo conn;
gridfs gfs;
 
if ((rv = mongo_connect(&conn, "127.0.0.1", 27017))) {
printf("mongo_connect(): %d\n", conn.err); goto end;
}
 
if ((rv = gridfs_init(&conn, "test", "fs", &gfs))) {
printf("gridfs_init(): %d\n", conn.err); goto end;
}
 
for (i = 0; i < 100; i++) {
sprintf(name, "%d.flv", count++);
if ((rv = gridfs_store_buffer(&gfs, data, 1024*1024, name, "video/x-flv"))) {
printf("insert failed: %s\n", name); fflush(stdout);
} else {
printf("insert success: %s\n", name); fflush(stdout);
}
}
 
end:
gridfs_destroy(&gfs);
mongo_disconnect(&conn);
mongo_destroy(&conn);
return 0;
}
 
static pid_t _spawn(int (*proc)()) {
pid_t pid;
 
if ((pid = fork()) == -1) {
fprintf(stderr, "fork failed\n");
}
 
if (pid != 0) {
fprintf(stderr, "child process %d created\n", (int)pid);
return pid;
}
 
proc();
exit(0);
return pid;
}
 
int main(int argc, char **argv) {
int i = 0;
for (i = 0; i < 2; i++) {
_spawn(_testgridfs);
count += 10000;
}
 
sleep(20);
return 0;
}

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.