本文整理汇总了C++中D函数的典型用法代码示例。如果您正苦于以下问题:C++ D函数的具体用法?C++ D怎么用?C++ D使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了D函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: pinger_body
static void *
pinger_body(void *data)
{
struct targ *targ = (struct targ *) data;
struct pollfd fds[1];
struct netmap_if *nifp = targ->nifp;
int i, rx = 0, n = targ->g->npackets;
fds[0].fd = targ->fd;
fds[0].events = (POLLIN);
static uint32_t sent;
struct timespec ts, now, last_print;
uint32_t count = 0, min = 1000000, av = 0;
if (targ->g->nthreads > 1) {
D("can only ping with 1 thread");
return NULL;
}
clock_gettime(CLOCK_REALTIME_PRECISE, &last_print);
while (n == 0 || (int)sent < n) {
struct netmap_ring *ring = NETMAP_TXRING(nifp, 0);
struct netmap_slot *slot;
char *p;
for (i = 0; i < 1; i++) {
slot = &ring->slot[ring->cur];
slot->len = targ->g->pkt_size;
p = NETMAP_BUF(ring, slot->buf_idx);
if (ring->avail == 0) {
D("-- ouch, cannot send");
} else {
pkt_copy(&targ->pkt, p, targ->g->pkt_size);
clock_gettime(CLOCK_REALTIME_PRECISE, &ts);
bcopy(&sent, p+42, sizeof(sent));
bcopy(&ts, p+46, sizeof(ts));
sent++;
ring->cur = NETMAP_RING_NEXT(ring, ring->cur);
ring->avail--;
}
}
/* should use a parameter to decide how often to send */
if (poll(fds, 1, 3000) <= 0) {
D("poll error/timeout on queue %d", targ->me);
continue;
}
/* see what we got back */
for (i = targ->qfirst; i < targ->qlast; i++) {
ring = NETMAP_RXRING(nifp, i);
while (ring->avail > 0) {
uint32_t seq;
slot = &ring->slot[ring->cur];
p = NETMAP_BUF(ring, slot->buf_idx);
clock_gettime(CLOCK_REALTIME_PRECISE, &now);
bcopy(p+42, &seq, sizeof(seq));
bcopy(p+46, &ts, sizeof(ts));
ts.tv_sec = now.tv_sec - ts.tv_sec;
ts.tv_nsec = now.tv_nsec - ts.tv_nsec;
if (ts.tv_nsec < 0) {
ts.tv_nsec += 1000000000;
ts.tv_sec--;
}
if (0) D("seq %d/%d delta %d.%09d", seq, sent,
(int)ts.tv_sec, (int)ts.tv_nsec);
if (ts.tv_nsec < (int)min)
min = ts.tv_nsec;
count ++;
av += ts.tv_nsec;
ring->avail--;
ring->cur = NETMAP_RING_NEXT(ring, ring->cur);
rx++;
}
}
//D("tx %d rx %d", sent, rx);
//usleep(100000);
ts.tv_sec = now.tv_sec - last_print.tv_sec;
ts.tv_nsec = now.tv_nsec - last_print.tv_nsec;
if (ts.tv_nsec < 0) {
ts.tv_nsec += 1000000000;
ts.tv_sec--;
}
if (ts.tv_sec >= 1) {
D("count %d min %d av %d",
count, min, av/count);
count = 0;
av = 0;
min = 100000000;
last_print = now;
}
}
return NULL;
}
示例2: pam_sm_setcred
PAM_EXTERN int pam_sm_setcred(pam_handle_t *pamh, int flags
, int argc, const char **argv)
{
const char *service=NULL, *tty=NULL;
const char *user=NULL;
int retval;
unsigned setting;
/* only interested in establishing credentials */
setting = flags;
if (!(setting & PAM_ESTABLISH_CRED)) {
D(("ignoring call - not for establishing credentials"));
return PAM_SUCCESS; /* don't fail because of this */
}
/* set service name */
if (pam_get_item(pamh, PAM_SERVICE, (const void **)&service)
!= PAM_SUCCESS || service == NULL) {
_log_err("cannot find the current service name");
return PAM_ABORT;
}
/* set username */
if (pam_get_user(pamh, &user, NULL) != PAM_SUCCESS || user == NULL
|| *user == '\0') {
_log_err("cannot determine the user's name");
return PAM_USER_UNKNOWN;
}
/* set tty name */
if (pam_get_item(pamh, PAM_TTY, (const void **)&tty) != PAM_SUCCESS
|| tty == NULL) {
D(("PAM_TTY not set, probing stdin"));
tty = ttyname(STDIN_FILENO);
if (tty == NULL) {
_log_err("couldn't get the tty name");
return PAM_ABORT;
}
if (pam_set_item(pamh, PAM_TTY, tty) != PAM_SUCCESS) {
_log_err("couldn't set tty name");
return PAM_ABORT;
}
}
if (strncmp("/dev/",tty,5) == 0) { /* strip leading /dev/ */
tty += 5;
}
/* good, now we have the service name, the user and the terminal name */
D(("service=%s", service));
D(("user=%s", user));
D(("tty=%s", tty));
#ifdef WANT_PWDB
/* We initialize the pwdb library and check the account */
retval = pwdb_start(); /* initialize */
if (retval == PWDB_SUCCESS) {
retval = check_account(service,tty,user); /* get groups */
(void) pwdb_end(); /* tidy up */
} else {
D(("failed to initialize pwdb; %s", pwdb_strerror(retval)));
_log_err("unable to initialize libpwdb");
retval = PAM_ABORT;
}
#else /* WANT_PWDB */
retval = check_account(service,tty,user); /* get groups */
#endif /* WANT_PWDB */
return retval;
}
示例3: showvmm
void
showvmm(void)
{
int i, n;
if (!vmm_fetched)
return;
for (i = 0; i < vmm_ncpus; ++i) {
struct kinfo_cputime d;
uint64_t cp_total = 0;
n = X_START + CPU_LABEL_W;
#define D(idx, field) \
(vmm_cur[idx].field - vmm_prev[idx].field) / (u_int)naptime
DRAW_ROW(n, CPU_START + i, 6, "%*u", D(i, v_timer));
DRAW_ROW(n, CPU_START + i, 8, "%*u", D(i, v_ipi));
DRAW_ROW(n, CPU_START + i, 8, "%*u", D(i, v_intr));
#define CPUD(dif, idx, field) \
do { \
dif.cp_##field = vmm_cptime_cur[idx].cp_##field - \
vmm_cptime_prev[idx].cp_##field; \
cp_total += dif.cp_##field; \
} while (0)
#define CPUV(dif, field) \
(dif.cp_##field * 100.0) / cp_total
CPUD(d, i, user);
CPUD(d, i, idle);
CPUD(d, i, intr);
CPUD(d, i, nice);
CPUD(d, i, sys);
if (cp_total == 0)
cp_total = 1;
DRAW_ROW(n, CPU_START + i, 6, "%*.1f",
CPUV(d, user) + CPUV(d, nice));
/* DRAW_ROW(n, CPU_START + i, 6, "%*.1f", CPUV(d, nice));*/
DRAW_ROW(n, CPU_START + i, 6, "%*.1f", CPUV(d, sys));
DRAW_ROW(n, CPU_START + i, 6, "%*.1f", CPUV(d, intr));
DRAW_ROW(n, CPU_START + i, 6, "%*.1f", CPUV(d, idle));
/*
* Display token collision count and the last-colliding
* token name.
*/
if (D(i, v_lock_colls) > 9999999)
DRAW_ROW(n, CPU_START + i, 8, "%*u", 9999999);
else
DRAW_ROW(n, CPU_START + i, 8, "%*u",
D(i, v_lock_colls));
if (D(i, v_lock_colls) == 0) {
DRAW_ROW2(n, CPU_START + i, 18, "%*.*s", "");
} else {
DRAW_ROW2(n, CPU_START + i, 18, "%*.*s",
vmm_cur[i].v_lock_name);
}
#undef D
#undef CPUV
#undef CPUD
#define CPUC(idx, field) vmm_cptime_cur[idx].cp_##field
#if 0
n = X_START + CPU_LABEL_W;
DRAW_ROW(n, CPU_STARTX + i, 15, "%-*s", CPUC(i, msg));
DRAW_ROW(n, CPU_STARTX + i, 35, "%-*s",
address_to_symbol((void *)(intptr_t)CPUC(i, stallpc),
&symctx));
#endif
#undef CPUC
}
}
示例4: __bro_openssl_write
int
__bro_openssl_write(BroConn *bc, uchar *buf, uint buf_size)
{
int n;
void *old_sig;
D_ENTER;
#ifdef BRO_DEBUG
if (bro_debug_messages)
{
unsigned int i = 0;
int last_hex = 0;
D(("Sending %u bytes: ", buf_size));
for (i = 0; i < buf_size; i++)
{
if (buf[i] >= 32 && buf[i] <= 126)
{
printf("%s%c", last_hex ? " " : "", buf[i]);
last_hex = 0;
}
else
{
printf(" 0x%.2x", buf[i]);
last_hex = 1;
}
}
printf("\n");
}
#endif
/* We may get a SIGPIPE if we write to a connection whose peer
* died. Since we don't know the application context in which
* we're running, we temporarily set the SIGPIPE handler to our
* own and then set it back to the old one after we wrote.
*/
old_sig = signal(SIGPIPE, SIG_IGN);
n = BIO_write(bc->bio, buf, buf_size);
if (n <= 0)
{
if (BIO_should_retry(bc->bio))
{
n = 0;
goto error_return;
}
print_errors();
__bro_openssl_shutdown(bc);
D(("Connection closed.\n"));
n = -1;
}
BIO_flush(bc->bio);
error_return:
if (old_sig != SIG_ERR)
signal(SIGPIPE, old_sig);
D_RETURN_(n);
}
示例5: mkgrplist
static int mkgrplist(char *buf, gid_t **list, int len)
{
int l,at=0;
int blks;
blks = blk_size(len);
D(("cf. blks=%d and len=%d", blks,len));
while ((l = find_member(buf,&at))) {
int edge;
if (len >= blks) {
gid_t *tmp;
D(("allocating new block"));
tmp = (gid_t *) realloc((*list)
, sizeof(gid_t) * (blks += GROUP_BLK));
if (tmp != NULL) {
(*list) = tmp;
} else {
_log_err("out of memory for group list");
free(*list);
(*list) = NULL;
return -1;
}
}
/* '\0' terminate the entry */
edge = (buf[at+l]) ? 1:0;
buf[at+l] = '\0';
D(("found group: %s",buf+at));
/* this is where we convert a group name to a gid_t */
#ifdef WANT_PWDB
{
int retval;
const struct pwdb *pw=NULL;
retval = pwdb_locate("group", PWDB_DEFAULT, buf+at
, PWDB_ID_UNKNOWN, &pw);
if (retval != PWDB_SUCCESS) {
_log_err("bad group: %s; %s", buf+at, pwdb_strerror(retval));
} else {
const struct pwdb_entry *pwe=NULL;
D(("group %s exists", buf+at));
retval = pwdb_get_entry(pw, "gid", &pwe);
if (retval == PWDB_SUCCESS) {
D(("gid = %d [%p]",* (const gid_t *) pwe->value,list));
(*list)[len++] = * (const gid_t *) pwe->value;
pwdb_entry_delete(&pwe); /* tidy up */
} else {
_log_err("%s group entry is bad; %s"
, pwdb_strerror(retval));
}
pw = NULL; /* break link - cached for later use */
}
}
#else
{
const struct group *grp;
grp = getgrnam(buf+at);
if (grp == NULL) {
_log_err("bad group: %s", buf+at);
} else {
D(("group %s exists", buf+at));
(*list)[len++] = grp->gr_gid;
}
}
#endif
/* next entry along */
at += l + edge;
}
D(("returning with [%p/len=%d]->%p",list,len,*list));
return len;
}
示例6: dynamic_parse
void dynamic_parse(void *data, pattern_t *pattern, size_t offset)
{
if(unlikely(!get_flags_dynamic_enable()))
return;
struct ssn_skb_values * ssv = ( struct ssn_skb_values *)data;
//struct l2ct_var_dpi * lvd = &(ssv->ssn->vars_dpi);
#if 0
if (unlikely(pattern->pattern_key.dynamic_current_phase - 1 & lvd->ac_state_tbl != pattern->pattern_key.dynamic_current_phase - 1)) {
if (i != 4) {
D("current_phase[%u], ldv[%p], ac_state_tbl[%u]\n", pattern->pattern_key.dynamic_current_phase,lvd, lvd->ac_state_tbl);
aaa =4;
}
lvd->ac_state_tbl = 0;
return;
}
lvd->ac_state_tbl |= pattern->pattern_key.dynamic_current_phase;
if (lvd->ac_state_tbl < pattern->pattern_key.dynamic_need_phase)
return;
lvd->ac_state_tbl = 0;
#endif
//get dns or ip + port list
//char *sp = ssv->payload + offset + pattern->pattern_len;
char *sp = ssv->payload + offset;
char *ep = ssv->payload + ssv->payload_len;
int pos = 0;
uint32_t ip;
uint32_t proto_mark;
uint16_t port = 0;
switch(pattern->pattern_key.dynamic_type) {
case 1:
{
if (pattern->pattern_key.dynamic_port && pattern->pattern_key.dynamic_port != (uint16_t)-1)
{
if(pattern->pattern_key.dynamic_dir && pattern->pattern_key.dynamic_port != ssv->ssn->sess_key.port_dst)
{
return;
}
if(0 == pattern->pattern_key.dynamic_dir && pattern->pattern_key.dynamic_port != ssv->ssn->sess_key.port_src)
{
return;
}
}
if (pattern->pattern_key.dynamic_dir)
{
if (pattern->pattern_key.dynamic_port == (uint16_t)-1) {
study_cache_try_get(ssv->ssn->sess_key.ip_dst, ssv->dport, ssv->ssn->proto_mark, 0, DYNAMIC_TIMEO);
#ifdef DYNAMIC_DEBUG
LOG("pattern[%s]add ip [%u]and port [%u.%u.%u.%u:%u] proto[%u] dynamic_indirect[%d]to study cache, common type, \n",
pattern->pattern_name, ssv->ssn->sess_key.ip_dst, IPQUADS(ssv->ssn->sess_key.ip_dst), ntohs(ssv->dport), ssv->ssn->proto_mark,pattern->pattern_key.dynamic_indirect);
#endif
} else {
study_cache_try_get(ssv->ssn->sess_key.ip_dst, pattern->pattern_key.dynamic_port, ssv->ssn->proto_mark, 0, DYNAMIC_TIMEO);
#ifdef DYNAMIC_DEBUG
LOG("pattern[%s]add ip [%u]and port [%u.%u.%u.%u:%u] proto[%u] dynamic_indirect[%d]to study cache, common type, \n",
pattern->pattern_name, ssv->ssn->sess_key.ip_dst, IPQUADS(ssv->ssn->sess_key.ip_dst), ntohs(pattern->pattern_key.dynamic_port), ssv->ssn->proto_mark,pattern->pattern_key.dynamic_indirect);
#endif
}
}
else
{
if (pattern->pattern_key.dynamic_port == (uint16_t)-1) {
study_cache_try_get(ssv->ssn->sess_key.ip_src, ssv->sport, ssv->ssn->proto_mark, 0, 0);
#ifdef DYNAMIC_DEBUG
LOG("pattern[%s]add ip [%u]and port [%u.%u.%u.%u:%u] proto[%u] dynamic_indirect[%d]to study cache, common type, \n",
pattern->pattern_name, ssv->ssn->sess_key.ip_src, IPQUADS(ssv->ssn->sess_key.ip_src), ntohs(ssv->sport), ssv->ssn->proto_mark,pattern->pattern_key.dynamic_indirect);
#endif
} else {
study_cache_try_get(ssv->ssn->sess_key.ip_src, pattern->pattern_key.dynamic_port, ssv->ssn->proto_mark, 0, 0);
#ifdef DYNAMIC_DEBUG
LOG("pattern[%s]add ip and port [%u.%u.%u.%u:%u] proto[%u] dynamic_indirect[%d]to study cache, common type\n",
pattern->pattern_name, IPQUADS(ssv->ssn->sess_key.ip_src), ntohs(pattern->pattern_key.dynamic_port), ssv->ssn->proto_mark,pattern->pattern_key.dynamic_indirect);
#endif
}
}
break;
}
case 2:
{
//printf("dns type\n");
parse_dns(data, pattern, offset);
break;
}
case 3:// ip:port[10.211.55.88:88]
{
do{
pos = subhex_in_mainhex(sp, ep - sp, pattern->pattern_key.ip_key, pattern->pattern_key.ip_key_len, 0);
if (pos <= 0)
return;
sp += pos;
for(; __isspace(*sp)||*sp == '"'||*sp == ':'; sp++) {
if (sp >= ep)
return;
//.........这里部分代码省略.........
示例7: try_connect
static int
try_connect(const char* host_and_port)
{
int status, sockfd = -1;
char* colon;
char* tmp;
char host[512];
char port[16];
struct addrinfo hints, *res, *res0;
D_ENTER;
memset(&hints, 0, sizeof(hints));
hints.ai_family = PF_UNSPEC;
hints.ai_protocol = IPPROTO_TCP;
hints.ai_socktype = SOCK_STREAM;
if ( ! (tmp = strdup(host_and_port)) )
{
D(("Out of memory.\n"));
D_RETURN_(-1);
}
if ( ! (colon = strrchr(tmp, ':')) )
{
D(("Invalid host:port string: %s\n", host_and_port));
free(tmp);
D_RETURN_(-1);
}
if ( ! colon[1] )
{
D(("Invalid port in host:port string: %s\n", host_and_port));
free(tmp);
D_RETURN_(-1);
}
*colon = '\0';
__bro_util_snprintf(host, sizeof(host), "%s", tmp);
__bro_util_snprintf(port, sizeof(port), "%s", colon + 1);
free(tmp);
D(("Trying to connect to [%s]:%s\n", host, port));
status = getaddrinfo(host, port, &hints, &res0);
if ( status != 0 )
{
D(("Error in getaddrinfo: %s\n", gai_strerror(status)));
D_RETURN_(-1);
}
for ( res = res0; res; res = res->ai_next )
{
sockfd = socket(res->ai_family, res->ai_socktype, res->ai_protocol);
if ( sockfd < 0 )
{
D(("socket() failed: %s\n", strerror(errno)));
continue;
}
if ( connect(sockfd, res->ai_addr, res->ai_addrlen) < 0 )
{
D(("connect() to %s failed: %s\n", host_and_port, strerror(errno)));
close(sockfd);
sockfd = -1;
continue;
}
break;
}
freeaddrinfo(res0);
D_RETURN_(sockfd);
}
示例8: receiver_body
static void *
receiver_body(void *data)
{
struct targ *targ = (struct targ *) data;
struct pollfd fds[1];
struct netmap_if *nifp = targ->nifp;
struct netmap_ring *rxring;
int i, received = 0;
if (setaffinity(targ->thread, targ->affinity))
goto quit;
/* setup poll(2) mechanism. */
memset(fds, 0, sizeof(fds));
fds[0].fd = targ->fd;
fds[0].events = (POLLIN);
/* unbounded wait for the first packet. */
for (;;) {
i = poll(fds, 1, 1000);
if (i > 0 && !(fds[0].revents & POLLERR))
break;
D("waiting for initial packets, poll returns %d %d", i, fds[0].revents);
}
/* main loop, exit after 1s silence */
gettimeofday(&targ->tic, NULL);
if (targ->g->use_pcap) {
for (;;) {
/* XXX should we poll ? */
pcap_dispatch(targ->g->p, targ->g->burst, receive_pcap, NULL);
}
} else {
while (1) {
/* Once we started to receive packets, wait at most 1 seconds
before quitting. */
do {
i = poll(fds, 1, 1 * 1000);
if (i < 0) {
gettimeofday(&targ->toc, NULL);
targ->toc.tv_sec -= 1; /* Subtract timeout time. */
goto rx_out;
}
} while (i==0);
for (i = targ->qfirst; i < targ->qlast; i++) {
int m;
rxring = NETMAP_RXRING(nifp, i);
if (rxring->avail == 0)
continue;
m = receive_packets(rxring, targ->g->burst,
SKIP_PAYLOAD);
received += m;
targ->count = received;
}
// tell the card we have read the data
//ioctl(fds[0].fd, NIOCRXSYNC, NULL);
}
}
rx_out:
targ->completed = 1;
targ->count = received;
quit:
/* reset the ``used`` flag. */
targ->used = 0;
return (NULL);
}
示例9: sender_body
static void *
sender_body(void *data)
{
struct targ *targ = (struct targ *) data;
struct pollfd fds[1];
struct netmap_if *nifp = targ->nifp;
struct netmap_ring *txring;
int i, n = targ->g->npackets / targ->g->nthreads, sent = 0;
int options = targ->g->options | OPT_COPY;
D("start");
if (setaffinity(targ->thread, targ->affinity))
goto quit;
/* setup poll(2) mechanism. */
memset(fds, 0, sizeof(fds));
fds[0].fd = targ->fd;
fds[0].events = (POLLOUT);
/* main loop.*/
gettimeofday(&targ->tic, NULL);
if (targ->g->use_pcap) {
int size = targ->g->pkt_size;
void *pkt = &targ->pkt;
pcap_t *p = targ->g->p;
for (i = 0; n == 0 || sent < n; i++) {
if (pcap_inject(p, pkt, size) != -1)
sent++;
if (i > 10000) {
targ->count = sent;
i = 0;
}
}
} else {
while (n == 0 || sent < n) {
/*
* wait for available room in the send queue(s)
*/
do {
i = poll(fds, 1, 2000);
if (i < 0) {
D("poll error/timeout on queue %d", targ->me);
goto quit;
}
} while (i==0);
/*
* scan our queues and send on those with room
*/
if (options & OPT_COPY && sent > 100000 && !(targ->g->options & OPT_COPY) ) {
D("drop copy");
options &= ~OPT_COPY;
}
for (i = targ->qfirst; i < targ->qlast; i++) {
int m, limit = targ->g->burst;
if (n > 0 && n - sent < limit)
limit = n - sent;
txring = NETMAP_TXRING(nifp, i);
if (txring->avail == 0)
continue;
m = send_pkts(txring, targ->pkts, targ->g->pkt_size,
limit, options, sent, targ->npkts);
sent += m;
targ->count = sent;
}
}
/* flush any remaining packets */
ioctl(fds[0].fd, NIOCTXSYNC, NULL);
/* final part: wait all the TX queues to be empty. */
for (i = targ->qfirst; i < targ->qlast; i++) {
txring = NETMAP_TXRING(nifp, i);
while (!NETMAP_TX_RING_EMPTY(txring)) {
ioctl(fds[0].fd, NIOCTXSYNC, NULL);
usleep(1); /* wait 1 tick */
}
}
}
gettimeofday(&targ->toc, NULL);
targ->completed = 1;
targ->count = sent;
quit:
/* reset the ``used`` flag. */
targ->used = 0;
return (NULL);
}
示例10: ponger_body
/*
* reply to ping requests
*/
static void *
ponger_body(void *data)
{
struct targ *targ = (struct targ *) data;
struct pollfd fds[1];
struct netmap_if *nifp = targ->nifp;
struct netmap_ring *txring, *rxring;
int i, rx = 0, sent = 0, n = targ->g->npackets;
fds[0].fd = targ->fd;
fds[0].events = (POLLIN);
if (targ->g->nthreads > 1) {
D("can only reply ping with 1 thread");
return NULL;
}
D("understood ponger %d but don't know how to do it", n);
while (n == 0 || sent < n) {
uint32_t txcur, txavail;
//#define BUSYWAIT
#ifdef BUSYWAIT
ioctl(fds[0].fd, NIOCRXSYNC, NULL);
#else
if (poll(fds, 1, 1000) <= 0) {
D("poll error/timeout on queue %d", targ->me);
continue;
}
#endif
txring = NETMAP_TXRING(nifp, 0);
txcur = txring->cur;
txavail = txring->avail;
/* see what we got back */
for (i = targ->qfirst; i < targ->qlast; i++) {
rxring = NETMAP_RXRING(nifp, i);
while (rxring->avail > 0) {
uint32_t cur = rxring->cur;
struct netmap_slot *slot = &rxring->slot[cur];
char *src, *dst;
src = NETMAP_BUF(rxring, slot->buf_idx);
//D("got pkt %p of size %d", src, slot->len);
rxring->avail--;
rxring->cur = NETMAP_RING_NEXT(rxring, cur);
rx++;
if (txavail == 0)
continue;
dst = NETMAP_BUF(txring,
txring->slot[txcur].buf_idx);
/* copy... */
pkt_copy(src, dst, slot->len);
txring->slot[txcur].len = slot->len;
/* XXX swap src dst mac */
txcur = NETMAP_RING_NEXT(txring, txcur);
txavail--;
sent++;
}
}
txring->cur = txcur;
txring->avail = txavail;
targ->count = sent;
#ifdef BUSYWAIT
ioctl(fds[0].fd, NIOCTXSYNC, NULL);
#endif
//D("tx %d rx %d", sent, rx);
}
return NULL;
}
示例11: callFunction
inline void callFunction(mxArray* plhs[], const mxArray*prhs[],
const int nlhs) {
if (!mexCheckType<T>(prhs[0]))
mexErrMsgTxt("type of argument 1 is not consistent");
if (mxIsSparse(prhs[0]))
mexErrMsgTxt("argument 1 should be full");
if (!mexCheckType<T>(prhs[1]))
mexErrMsgTxt("type of argument 2 is not consistent");
if (mxIsSparse(prhs[1]))
mexErrMsgTxt("argument 2 should be full");
if (!mexCheckType<bool>(prhs[2]))
mexErrMsgTxt("type of argument 3 should be boolean");
if (mxIsSparse(prhs[2]))
mexErrMsgTxt("argument 3 should be full");
if (!mxIsStruct(prhs[3]))
mexErrMsgTxt("argument 3 should be struct");
T* prX = reinterpret_cast<T*>(mxGetPr(prhs[0]));
const mwSize* dimsX=mxGetDimensions(prhs[0]);
int n=static_cast<int>(dimsX[0]);
int M=static_cast<int>(dimsX[1]);
T* prD = reinterpret_cast<T*>(mxGetPr(prhs[1]));
const mwSize* dimsD=mxGetDimensions(prhs[1]);
int nD=static_cast<int>(dimsD[0]);
int K=static_cast<int>(dimsD[1]);
if (n != nD) mexErrMsgTxt("argument sizes are not consistent");
bool* prmask = reinterpret_cast<bool*>(mxGetPr(prhs[2]));
const mwSize* dimsM=mxGetDimensions(prhs[2]);
int nM=static_cast<int>(dimsM[0]);
int mM=static_cast<int>(dimsM[1]);
if (nM != n || mM != M) mexErrMsgTxt("argument sizes are not consistent");
Matrix<T> X(prX,n,M);
Matrix<T> D(prD,n,K);
SpMatrix<T> alpha;
mxArray* pr_L=mxGetField(prhs[3],0,"L");
if (!pr_L) mexErrMsgTxt("Missing field L in param");
const mwSize* dimsL=mxGetDimensions(pr_L);
int sizeL=static_cast<int>(dimsL[0])*static_cast<int>(dimsL[1]);
mxArray* pr_eps=mxGetField(prhs[3],0,"eps");
if (!pr_eps) mexErrMsgTxt("Missing field eps in param");
const mwSize* dimsE=mxGetDimensions(pr_eps);
int sizeE=static_cast<int>(dimsE[0])*static_cast<int>(dimsE[1]);
int numThreads = getScalarStructDef<int>(prhs[3],"numThreads",-1);
Matrix<bool> mask(prmask,n,M);
if (nlhs == 2) {
int L=MIN(n,MIN(static_cast<int>(mxGetScalar(pr_L)),K));
plhs[1]=createMatrix<T>(K,L);
T* pr_path=reinterpret_cast<T*>(mxGetPr(plhs[1]));
Matrix<T> path(pr_path,K,L);
path.setZeros();
T eps=static_cast<T>(mxGetScalar(pr_eps));
omp_mask<T>(X,D,alpha,mask,L,eps,numThreads,path);
} else {
if (sizeL == 1) {
int L=static_cast<int>(mxGetScalar(pr_L));
if (sizeE == 1) {
T eps=static_cast<T>(mxGetScalar(pr_eps));
omp_mask<T>(X,D,alpha,mask,L,eps,numThreads);
} else {
T* pE = reinterpret_cast<T*>(mxGetPr(pr_eps));
omp_mask<T>(X,D,alpha,mask,L,pE,numThreads);
}
} else {
if (!mexCheckType<int>(pr_L))
mexErrMsgTxt("Type of param.L should be int32");
int* pL = reinterpret_cast<int*>(mxGetPr(pr_L));
if (sizeE == 1) {
T eps=static_cast<T>(mxGetScalar(pr_eps));
omp_mask<T>(X,D,alpha,mask,pL,eps,numThreads);
} else {
T* pE = reinterpret_cast<T*>(mxGetPr(pr_eps));
omp_mask<T>(X,D,alpha,mask,pL,pE,numThreads,true,true);
}
}
}
convertSpMatrix(plhs[0],K,M,alpha.n(),alpha.nzmax(),alpha.v(),alpha.r(),
alpha.pB());
}
示例12: NP
int NP() { printf("<NP>"); D(); N(); printf("</NP>"); }
示例13: xvba_common_Initialize
// vaInitialize
static VAStatus xvba_common_Initialize(xvba_driver_data_t *driver_data)
{
int xvba_version;
int fglrx_major_version, fglrx_minor_version, fglrx_micro_version;
unsigned int device_id;
driver_data->x11_dpy_local = XOpenDisplay(driver_data->x11_dpy_name);
if (!driver_data->x11_dpy_local)
return VA_STATUS_ERROR_UNKNOWN;
if (!fglrx_is_dri_capable(driver_data->x11_dpy, driver_data->x11_screen))
return VA_STATUS_ERROR_UNKNOWN;
if (!fglrx_get_version(driver_data->x11_dpy, driver_data->x11_screen,
&fglrx_major_version,
&fglrx_minor_version,
&fglrx_micro_version))
return VA_STATUS_ERROR_UNKNOWN;
D(bug("FGLRX driver version %d.%d.%d detected\n",
fglrx_major_version, fglrx_minor_version, fglrx_micro_version));
if (!fglrx_check_version(8,80,5)) {
xvba_error_message("FGLRX driver version 8.80.5 (Catalyst 10.12) or later is required\n");
return VA_STATUS_ERROR_UNKNOWN;
}
if (!fglrx_get_device_id(driver_data->x11_dpy, driver_data->x11_screen,
&device_id))
return VA_STATUS_ERROR_UNKNOWN;
D(bug("FGLRX device ID 0x%04x\n", device_id));
driver_data->device_id = device_id;
switch (device_id & 0xff00) {
case 0x6700: // Radeon HD 6000 series
case 0x6800: // Radeon HD 5000 series
D(bug("Evergreen GPU detected\n"));
driver_data->is_evergreen_gpu = 1;
break;
case 0x9800: // Fusion series
D(bug("Fusion IGP detected\n"));
driver_data->is_evergreen_gpu = 1;
driver_data->is_fusion_igp = 1;
break;
}
if (xvba_gate_init() < 0)
return VA_STATUS_ERROR_UNKNOWN;
if (xvba_query_extension(driver_data->x11_dpy, &xvba_version) < 0)
return VA_STATUS_ERROR_UNKNOWN;
D(bug("XvBA version %d.%d detected\n",
(xvba_version >> 16) & 0xffff, xvba_version & 0xffff));
if (!xvba_check_version(0,74)) {
xvba_information_message("Please upgrade to XvBA >= 0.74\n");
return VA_STATUS_ERROR_UNIMPLEMENTED;
}
driver_data->xvba_context = xvba_create_context(driver_data->x11_dpy, None);
if (!driver_data->xvba_context)
return VA_STATUS_ERROR_UNKNOWN;
sprintf(driver_data->va_vendor, "%s %s - %d.%d.%d",
XVBA_STR_DRIVER_VENDOR,
XVBA_STR_DRIVER_NAME,
XVBA_VIDEO_MAJOR_VERSION,
XVBA_VIDEO_MINOR_VERSION,
XVBA_VIDEO_MICRO_VERSION);
if (XVBA_VIDEO_PRE_VERSION > 0) {
const int len = strlen(driver_data->va_vendor);
sprintf(&driver_data->va_vendor[len], ".pre%d", XVBA_VIDEO_PRE_VERSION);
}
CREATE_HEAP(config, CONFIG);
CREATE_HEAP(context, CONTEXT);
CREATE_HEAP(surface, SURFACE);
CREATE_HEAP(buffer, BUFFER);
CREATE_HEAP(output, OUTPUT);
CREATE_HEAP(image, IMAGE);
CREATE_HEAP(subpicture, SUBPICTURE);
return VA_STATUS_SUCCESS;
}
示例14: __bro_openssl_init
int
__bro_openssl_init(void)
{
static int deja_vu = FALSE;
int use_ssl = FALSE;
const char *our_cert, *our_key, *our_pass, *ca_cert;
D_ENTER;
if (deja_vu)
D_RETURN_(TRUE);
deja_vu = TRUE;
/* I hope these should go before SSL_library_init() -- not even the
* O'Reilly book is clear on that. :( --cpk
*/
if (global_ctx)
{
if (global_ctx->id_func)
CRYPTO_set_id_callback(global_ctx->id_func);
if (global_ctx->lock_func)
CRYPTO_set_locking_callback(global_ctx->lock_func);
if (global_ctx->dl_create_func)
CRYPTO_set_dynlock_create_callback(global_ctx->dl_create_func);
if (global_ctx->dl_lock_func)
CRYPTO_set_dynlock_lock_callback(global_ctx->dl_lock_func);
if (global_ctx->dl_free_func)
CRYPTO_set_dynlock_destroy_callback(global_ctx->dl_free_func);
}
SSL_library_init();
prng_init();
#ifdef BRO_DEBUG
D(("Loading OpenSSL error strings for debugging\n"));
SSL_load_error_strings();
#endif
if (__bro_conf_get_int("/broccoli/use_ssl", &use_ssl) && ! use_ssl)
{
D(("SSL disabled in configuration, not using SSL.\n"));
D_RETURN_(TRUE);
}
our_cert = __bro_conf_get_str("/broccoli/host_cert");
our_key = __bro_conf_get_str("/broccoli/host_key");
if (our_key == NULL)
{
/* No private key configured; get it from the certificate file */
our_key = our_cert;
}
if (our_cert == NULL)
{
if (use_ssl)
{
D(("SSL requested but host certificate not given -- aborting.\n"));
D_RETURN_(FALSE);
}
else
{
D(("use_ssl not used and host certificate not given -- not using SSL.\n"));
D_RETURN_(TRUE);
}
}
if (our_key == NULL)
{
if (use_ssl)
{
D(("SSL requested but host key not given -- aborting.\n"));
D_RETURN_(FALSE);
}
else
{
D(("use_ssl not used and host key not given -- not using SSL.\n"));
D_RETURN_(TRUE);
}
}
/* At this point we either haven't seen use_ssl but a host_cert, or
* we have seen use_ssl and it is set to true. Either way, we attempt
* to set up an SSL connection now and abort if this fails in any way.
*/
if (! (ctx = SSL_CTX_new(SSLv3_method())))
D_RETURN_(FALSE);
/* We expect things to be stored in PEM format, which means that we
* can store multiple entities in one file. In this case, our own
* certificate is expected to be stored along with the private key
* in the file pointed to by preference setting /broccoli/certificate.
*
* See page 121 in O'Reilly's OpenSSL book for details.
*/
if (SSL_CTX_use_certificate_chain_file(ctx, our_cert) != 1)
{
D(("Error loading certificate from '%s'.\n", our_cert));
//.........这里部分代码省略.........
示例15: main
int main()
{
poc();
SLabel A("A"); SExpressionLabel *pa = A.GetPtr();
SLabel B("B"); SExpressionLabel *pb = B.GetPtr();
SLabel C("C"); SExpressionLabel *pc = C.GetPtr();
SLabel D("D"); SExpressionLabel *pd = D.GetPtr();
SLabel E("E"); SExpressionLabel *pe = E.GetPtr();
SLabel F("F"); SExpressionLabel *pf = F.GetPtr();
SExpressionLabel *pall[] = { pa, pb, pc, pd, pe, pf };
try {
TestSection("IntelibBindingsSet");
TestSubsection("Creation");
{
IntelibBindingsSet t;
TESTB("empty0", !t.GetBinding(pa));
TESTB("empty25", !t.GetBinding(pb));
*(t.AddBinding(pb)) = SReference(2525);
TESTTR("root_only", *(t.GetBinding(pb)), "2525");
*(t.AddBinding(pc)) = SReference(3636);
TESTB("root_still_there", t.GetBinding(pb));
TESTTR("root_still_has_value", *(t.GetBinding(pb)), "2525");
TESTB("second_val_exists", t.GetBinding(pc));
TESTTR("second_val", *(t.GetBinding(pc)), "3636");
TESTB("root_still_there", t.GetBinding(pb));
}
TestSubsection("Allocation");
{
IntelibBindingsSet t;
SReference* loc[4];
for(int i = 0; i < 4; i++) {
loc[i] = t.AddBinding(pall[i]);
*loc[i] = (i+1) * 1000;
}
t.AddBinding(pf);
SReference *l1 = t.GetBinding(pb);
TESTB("still_there_after_resize", l1);
TESTTR("still_value_after_resize", *l1, "2000");
SReference *l0 = t.GetBinding(pa);
TESTB("root_there_after_resize", l0);
TESTTR("root_value_after_resize", *l0, "1000");
//TESTB("resize_really_done", l1 != loc[1]);
}
TestSubsection("Iterator");
{
IntelibBindingsSet t;
IntelibBindingsSet::Iterator iter0(t);
SReference ref;
const SExpressionLabel *key;
TESTB("iterator_on_empty", !iter0.GetNext(key, ref));
*(t.AddBinding(pa)) = SReference(2);
*(t.AddBinding(pb)) = SReference(20);
*(t.AddBinding(pc)) = SReference(200);
IntelibBindingsSet::Iterator iter1(t);
int sum2 = 0;
while(iter1.GetNext(key, ref)) {
if(ref.GetPtr()) sum2 += ref.GetInt();
}
TEST("iterator_values", sum2, 222);
}
TestSubsection("LotsOfBindings");
{
IntelibBindingsSet t;
*(t.AddBinding(pa)) = SReference(1);
*(t.AddBinding(pb)) = SReference(2);
*(t.AddBinding(pc)) = SReference(3);
*(t.AddBinding(pd)) = SReference(4);
*(t.AddBinding(pe)) = SReference(5);
*(t.AddBinding(pf)) = SReference(6);
TESTB("value_there_1", t.GetBinding(pa));
TESTB("value_there_2", t.GetBinding(pb));
TESTB("value_there_3", t.GetBinding(pc));
TESTB("value_there_4", t.GetBinding(pd));
TESTB("value_there_5", t.GetBinding(pe));
TESTB("value_there_6", t.GetBinding(pf));
}
TestScore();
}
catch(const IntelibX &ex) {
printf("Caught IntelibX: %s\n%s\n",
ex.Description(),
ex.Parameter().GetPtr() ?
ex.Parameter()->TextRepresentation().c_str()
: ""
);
}
catch(...) {
printf("Something strange caught\n");
}
poc();
return 0;
}