static void db_tag_blob(int bid, const char **tags, size_t ntags) { int tid; size_t i; sqlite3_stmt *stmt; const char *sql = "INSERT INTO fk_blobs_tags (blob_id, tag_id) " "VALUES (?, ?)"; err_assert(bid > 0); if(ntags < 1) return; DB_STMT_PREP(sql, &stmt); DB_BIND_INT(stmt, 1, bid); for(i = 0; i < ntags; i++) { if(i > 0) DB_STMT_RESET(stmt); tid = db_find_or_create_tag(tags[i]); DB_BIND_INT(stmt, 2, tid); if(db_stmt_step(stmt) == 0) err_panic(0, "expected SQLITE_DONE from %s: ", sql); } DB_STMT_FINALIZE(stmt); }
int main (int argc, char **argv) { int i; char *target = NULL; char *mxdir = NULL; char *propfile = NULL; FILE *file; shared_init(32*1024*1024); err_init(); log_init(LOG_LEVEL); mman_init(); while (1) { char c = getopt(argc, argv, "n:d:p:"); if (c == -1) { break; } switch (c) { case 'd': mxdir = optarg; break; case 'n': target = optarg; break; case 'p': propfile = optarg; break; } } if (argc < 2) { usage(); } else { c = mxc_create(); c->mxdir = mxdir; c->target = target; prop_addFromFile(c->props, propfile); for (i = optind; i < argc; i++) { c->filename = argv[i]; file = fopen(argv[i], "r"); err_assert(file != NULL, err_f("IOError")); yyin = file; yylineno = 1; yyparse(); } mxc_emitIncludes(c); mxc_emitExports(c); mxc_emitInterface(c); mxc_emitCode(c); mxc_emitBuildScript(c); //mxc_free(c); } shared_cleanup(); return 0; }
int xs_sock_init (xs_sock *self) { int rc; /* Set virtual members to invalid values to catch any potential errors. */ memset (&self->vfptr, 0, sizeof (self->vfptr)); self->vfptr.term = xs_sock_term; self->vfptr.setopt = xs_sock_setopt; self->vfptr.getopt = xs_sock_getopt; self->type = -1; xs_mutex_init (&self->sync); rc = pthread_cond_init (&self->writeable, NULL); errnum_assert (rc); rc = pthread_cond_init (&self->readable, NULL); errnum_assert (rc); int sv [2]; rc = socketpair (AF_UNIX, SOCK_STREAM, 0, sv); rc = xs_tcpout_init (&self->out, sv [0], xs_sock_send_done, self); err_assert (rc); }
int xs_instream_recv (xs_instream *self, xs_msg *msg) { int rc; ssize_t nbytes; /* If there's a message available, return is straight away. */ if (self->state == 2) { xs_msg_move (msg, &self->msg); self->state = 0; return 0; } /* If message is being asynchronously received at the moment, there's no message to return yet. */ if (self->state == 1) return -EINPROGRESS; /* Try to read the message in a synchronous way. */ nbytes = recv (self->fd, self->sizebuf, 8, MSG_DONTWAIT); /* Sanitation of the result. */ if (unlikely (nbytes == 0)) { errno = ECONNREFUSED; nbytes = -1; } else if (unlikely (nbytes == -1 && (errno == EAGAIN || errno == EWOULDBLOCK))) nbytes = 0; errno_assert (nbytes >= 0); if (nbytes < 8) { self->recvd = nbytes; /* TODO: xs_instream_launch_async (self); */ return -EINPROGRESS; } rc = xs_msg_init (&self->msg, xs_getll (self->sizebuf)); err_assert (rc); nbytes = recv (self->fd, xs_msg_data (&self->msg), xs_msg_size (&self->msg), MSG_DONTWAIT); /* Sanitation of the result. */ if (unlikely (nbytes == 0)) { errno = ECONNREFUSED; nbytes = -1; } else if (unlikely (nbytes == -1 && (errno == EAGAIN || errno == EWOULDBLOCK))) nbytes = 0; if (nbytes < xs_msg_size (&self->msg)) { self->recvd = nbytes + 8; /* TODO: xs_instream_launch_async (self); */ return -EINPROGRESS; } /* Synchronous receive was successful. */ xs_msg_move (msg, &self->msg); return 0; }