char * storeSwapMetaPack(tlv * tlv_list, int *length) { int buflen = 0; tlv *t; int j = 0; char *buf; assert(length != NULL); buflen++; /* STORE_META_OK */ buflen += sizeof(int); /* size of header to follow */ for (t = tlv_list; t; t = t->next) buflen += sizeof(char) + sizeof(int) + t->length; buf = xmalloc(buflen); buf[j++] = (char) STORE_META_OK; xmemcpy(&buf[j], &buflen, sizeof(int)); j += sizeof(int); for (t = tlv_list; t; t = t->next) { buf[j++] = (char) t->type; xmemcpy(&buf[j], &t->length, sizeof(int)); j += sizeof(int); xmemcpy(&buf[j], t->value, t->length); j += t->length; } assert((int) j == buflen); *length = buflen; return buf; }
void netdbBinaryExchange(StoreEntry * s) { http_reply *reply = s->mem_obj->reply; #if USE_ICMP netdbEntry *n; int i; int j; int rec_sz; char *buf; struct in_addr addr; storeBuffer(s); httpReplyReset(reply); httpReplySetHeaders(reply, HTTP_OK, "OK", NULL, -1, squid_curtime, -1); httpReplySwapOut(reply, s); rec_sz = 0; rec_sz += 1 + sizeof(addr.s_addr); rec_sz += 1 + sizeof(int); rec_sz += 1 + sizeof(int); buf = memAllocate(MEM_4K_BUF); i = 0; hash_first(addr_table); while ((n = (netdbEntry *) hash_next(addr_table))) { if (0.0 == n->rtt) continue; if (n->rtt > 60000) /* RTT > 1 MIN probably bogus */ continue; if (!safe_inet_addr(n->network, &addr)) continue; buf[i++] = (char) NETDB_EX_NETWORK; xmemcpy(&buf[i], &addr.s_addr, sizeof(addr.s_addr)); i += sizeof(addr.s_addr); buf[i++] = (char) NETDB_EX_RTT; j = htonl((int) (n->rtt * 1000)); xmemcpy(&buf[i], &j, sizeof(int)); i += sizeof(int); buf[i++] = (char) NETDB_EX_HOPS; j = htonl((int) (n->hops * 1000)); xmemcpy(&buf[i], &j, sizeof(int)); i += sizeof(int); if (i + rec_sz > 4096) { storeAppend(s, buf, i); i = 0; } } if (i > 0) { storeAppend(s, buf, i); i = 0; } assert(0 == i); storeBufferFlush(s); memFree(buf, MEM_4K_BUF); #else httpReplyReset(reply); httpReplySetHeaders(reply, HTTP_BAD_REQUEST, "Bad Request", NULL, -1, -1, -1); httpReplySwapOut(reply, s); storeAppendPrintf(s, "NETDB support not compiled into this Squid cache.\n"); #endif storeComplete(s); }
struct variable_list * snmp_var_clone(struct variable_list *Src) { struct variable_list *Dest; #ifdef DEBUG_VARS printf("VARS: Cloning.\n"); #endif Dest = (struct variable_list *) xmalloc(sizeof(struct variable_list)); if (Dest == NULL) { snmp_set_api_error(SNMPERR_OS_ERR); return (NULL); } #ifdef DEBUG_VARS printf("VARS: Copying entire variable list. (Size %d)\n", sizeof(struct variable_list)); #endif xmemcpy((char *) Dest, (char *) Src, sizeof(struct variable_list)); if (Src->name != NULL) { Dest->name = (oid *) xmalloc(Src->name_length * sizeof(oid)); if (Dest->name == NULL) { snmp_set_api_error(SNMPERR_OS_ERR); xfree(Dest); return (NULL); } #ifdef DEBUG_VARS printf("VARS: Copying name OID. (Size %d)\n", Src->name_length); #endif xmemcpy((char *) Dest->name, (char *) Src->name, Src->name_length * sizeof(oid)); } /* CISCO Catalyst 2900 returns NULL strings as data of length 0. */ if ((Src->val.string != NULL) && (Src->val_len)) { Dest->val.string = (u_char *) xmalloc(Src->val_len); if (Dest->val.string == NULL) { snmp_set_api_error(SNMPERR_OS_ERR); xfree(Dest->name); xfree(Dest); return (NULL); } #ifdef DEBUG_VARS printf("VARS: Copying value (Size %d)\n", Src->val_len); #endif xmemcpy((char *) Dest->val.string, (char *) Src->val.string, Src->val_len); } #ifdef DEBUG_VARS printf("VARS: Cloned %x.\n", (unsigned int) Dest); #endif #ifdef DEBUG_VARS_MALLOC printf("VARS: Cloned (%x)\n", (unsigned int) Dest); printf("VARS: Name is (%x)\n", (unsigned int) Dest->name); #endif return (Dest); }
/* 和ReadThreeBackupClock类似,但是当有备份块的数据出错的时候,要记录错误 */ void ReadThreeBackup(uint ReadAdd1, uint ReadAdd2, uint ReadAdd3, uchar len, uint BackupErrAdd, uint BackupALLErrAdd, uchar *pOut) { uchar bkBlockFlg = BK_1ST; uchar tmp, i; uchar bkbuf[3*len]; uint eeAddr[3] = {ReadAdd1, ReadAdd2, ReadAdd3,}; for(i=0; i<3; i++) { BackupErrAdd += 2*i; Read512(bkbuf+len*i, eeAddr[i], len); tmp = Check_CS(bkbuf+len*i, len); if(TRUE == tmp) { bkBlockFlg |= (0x01<<i); } else { bkBlockFlg &= ~(0x01<<i); E2PINC(BackupErrAdd, 2); } } if(0x00 == bkBlockFlg) { E2PINC(BackupALLErrAdd, 2); ThreeBferro = 0xAA; } switch(bkBlockFlg) { case 0x00: Eeprom_err |= 0x04; xmemcpy(bkbuf, pOut, len); break; case 0x01: //第一备份正确 case 0x03: //第一、二备份正确 case 0x05: //第一、三备份正确 case 0x07: //三备份都正确 xmemcpy(bkbuf, pOut len); break; case 0x02: //第二备份正确 case 0x06: //第二、三备份正确 xmemcpy(bkbuf+len, pOut, len); break; case 0x04: //第三备份正确 xmemcpy(bkbuf+len*2, pOut, len); break; default: break; } }
/* 对于时钟备份数据,和能量备份数据的处理不同点:有多于一块的备份正确,则读最靠左的那个块 写三备份的策略和能量三备份不同(? how and why) */ void ReadThreeBackupClock(uint ReadAdd1, uint ReadAdd2, uint ReadAdd3, uchar len, uchar *pOut) { uchar bkBlockFlg = BK_1ST; uchar i, tmp; uchar bkbuf[3*len]; uint eeAddr[3] = {ReadAdd1, ReadAdd2, ReadAdd3}; if(0 == len) { return; } ThreeBferro = 0x55; //区别在于不用指出下一次写的时候要将数据写到哪个备份 for(i=0; i<3; i++) { Read512(bkbuf+len*i, eeAddr[i], len); tmp = Check_CS(bkbuf+len*i, len); if(TRUE == tmp) { bkBlockFlg |= (0x01<<i); } else { bkBlockFlg &= ~(0x01<<i); } } switch(bkBlockFlg) { case 0x00: case 0x01: //第一备份正确 case 0x03: //第一、二备份正确 case 0x05: //第一、三备份正确 case 0x07: //三备份都正确 xmemcpy(bkbuf, pOut len); break; case 0x02: //第二备份正确 case 0x06: //第二、三备份正确 xmemcpy(bkbuf+len, pOut, len); break; case 0x04: //第三备份正确 xmemcpy(bkbuf+len*2, pOut, len); break; default: break; } }
int ringbuf_push_back(struct ringbuf *buf, const void *src, size_t n) { if (buf->capacity < n) return -1; size_t n1 = min(buf->capacity - buf->write_pos, n); xmemcpy(buf->data + buf->write_pos, src, n1); if (n > n1) xmemcpy(buf->data, (uint8_t *) src + n1, n - n1); buf->bytes_filled = min(buf->bytes_filled + n, buf->capacity); buf->write_pos = (buf->write_pos + n) % buf->capacity; return 0; }
static int process_request(cachemgr_request * req) { const struct hostent *hp; static struct sockaddr_in S; int s; int l; static char buf[2 * 1024]; if (req == NULL) { auth_html(CACHEMGR_HOSTNAME, CACHE_HTTP_PORT, ""); return 1; } if (req->hostname == NULL) { req->hostname = xstrdup(CACHEMGR_HOSTNAME); } if (req->port == 0) { req->port = CACHE_HTTP_PORT; } if (req->action == NULL) { req->action = xstrdup(""); } if (!strcmp(req->action, "authenticate")) { auth_html(req->hostname, req->port, req->user_name); return 0; } if ((s = socket(PF_INET, SOCK_STREAM, 0)) < 0) { snprintf(buf, 1024, "socket: %s\n", xstrerror()); error_html(buf); return 1; } memset(&S, '\0', sizeof(struct sockaddr_in)); S.sin_family = AF_INET; if ((hp = gethostbyname(req->hostname)) != NULL) { assert(hp->h_length <= sizeof(S.sin_addr.s_addr)); xmemcpy(&S.sin_addr.s_addr, hp->h_addr, hp->h_length); } else if (safe_inet_addr(req->hostname, &S.sin_addr)) (void) 0; else { snprintf(buf, 1024, "Unknown host: %s\n", req->hostname); error_html(buf); return 1; } S.sin_port = htons(req->port); if (connect(s, (struct sockaddr *) &S, sizeof(struct sockaddr_in)) < 0) { snprintf(buf, 1024, "connect: %s\n", xstrerror()); error_html(buf); return 1; } l = snprintf(buf, sizeof(buf), "GET cache_object://%s/%s HTTP/1.0\r\n" "Accept: */*\r\n" "%s" /* Authentication info or nothing */ "\r\n", req->hostname, req->action, make_auth_header(req)); write(s, buf, l); debug(1) fprintf(stderr, "wrote request: '%s'\n", buf); return read_reply(s, req); }
static void logfile_mod_udp_writeline(Logfile * lf, const char *buf, size_t len) { l_udp_t *ll = (l_udp_t *) lf->data; if (0 == ll->bufsz) { /* buffering disabled */ logfile_mod_udp_write(lf, buf, len); return; } if (ll->offset > 0 && ll->offset + len + 4 > ll->bufsz) logfile_mod_udp_flush(lf); if (len > ll->bufsz) { /* too big to fit in buffer */ logfile_mod_udp_write(lf, buf, len); return; } /* buffer it */ xmemcpy(ll->buf + ll->offset, buf, len); ll->offset += len; assert(ll->offset >= 0); assert((size_t) ll->offset <= ll->bufsz); }
void * icpCreateMessage( icp_opcode opcode, int flags, const char *url, int reqnum, int pad) { char *buf = NULL; icp_common_t *headerp = NULL; char *urloffset = NULL; int buf_len; buf_len = sizeof(icp_common_t) + strlen(url) + 1; if (opcode == ICP_QUERY) buf_len += sizeof(u_num32); buf = xcalloc(buf_len, 1); headerp = (icp_common_t *) (void *) buf; headerp->opcode = (char) opcode; headerp->version = ICP_VERSION_CURRENT; headerp->length = (u_short) htons(buf_len); headerp->reqnum = htonl(reqnum); headerp->flags = htonl(flags); headerp->pad = htonl(pad); headerp->shostid = theOutICPAddr.s_addr; urloffset = buf + sizeof(icp_common_t); if (opcode == ICP_QUERY) urloffset += sizeof(u_num32); xmemcpy(urloffset, url, strlen(url)); return buf; }
static void idnsAddNameserver(const char *buf) { struct in_addr A; if (!safe_inet_addr(buf, &A)) { debug(78, 0) ("WARNING: rejecting '%s' as a name server, because it is not a numeric IP address\n", buf); return; } if (nns == nns_alloc) { int oldalloc = nns_alloc; ns *oldptr = nameservers; if (nns_alloc == 0) nns_alloc = 2; else nns_alloc <<= 1; nameservers = xcalloc(nns_alloc, sizeof(*nameservers)); if (oldptr && oldalloc) xmemcpy(nameservers, oldptr, oldalloc * sizeof(*nameservers)); if (oldptr) safe_free(oldptr); } assert(nns < nns_alloc); nameservers[nns].S.sin_family = AF_INET; nameservers[nns].S.sin_port = htons(DOMAIN_PORT); nameservers[nns].S.sin_addr.s_addr = A.s_addr; debug(78, 3) ("idnsAddNameserver: Added nameserver #%d: %s\n", nns, inet_ntoa(nameservers[nns].S.sin_addr)); nns++; }
const cache_key * storeKeyDup(const cache_key * key) { cache_key *dup = memAllocate(MEM_MD5_DIGEST); xmemcpy(dup, key, MD5_DIGEST_CHARS); return dup; }
/* * EFFECTS: * return the first coord which < k */ int nmb_get_right_coord(struct nmb *nmb, struct msg *right, struct pma_coord *coord) { int slot_idx = nmb->pma->used - 1; /* is uesd not used - 1 */ int array_idx = nmb->pma->slots[slot_idx]->used; coord->slot_idx = slot_idx; coord->array_idx = array_idx; if (right) { void *retval; struct nmb_entry *entry = xcalloc(1, NMB_ENTRY_SIZE + right->size); entry->keylen = right->size; xmemcpy((char*)entry + NMB_ENTRY_SIZE, right->data, right->size); pma_find_plus(nmb->pma, entry, _nmb_entry_key_compare, nmb, &retval, coord); xfree(entry); } return 1; }
static void lookup(const char *buf) { const struct hostent *result = NULL; int reverse = 0; int ttl = 0; int retry = 0; int i; struct in_addr addr; if (0 == strcmp(buf, "$shutdown")) exit(0); if (0 == strcmp(buf, "$hello")) { printf("$alive\n"); return; } /* check if it's already an IP address in text form. */ for (;;) { if (safe_inet_addr(buf, &addr)) { reverse = 1; result = gethostbyaddr((char *) &addr.s_addr, 4, AF_INET); } else { result = gethostbyname(buf); } if (NULL != result) break; if (h_errno != TRY_AGAIN) break; if (++retry == 3) break; sleep(1); } if (NULL == result) { if (h_errno == TRY_AGAIN) { printf("$fail Name Server for domain '%s' is unavailable.\n", buf); } else { printf("$fail DNS Domain '%s' is invalid: %s.\n", buf, my_h_msgs(h_errno)); } return; } #if LIBRESOLV_DNS_TTL_HACK /* DNS TTL handling - [email protected] * for first try it's a dirty hack, by hacking getanswer * to place the ttl in a global variable */ if (_dns_ttl_ > -1) ttl = _dns_ttl_; #endif if (reverse) { printf("$name %d %s\n", ttl, result->h_name); return; } printf("$addr %d", ttl); for (i = 0; NULL != result->h_addr_list[i]; i++) { if (32 == i) break; xmemcpy(&addr, result->h_addr_list[i], sizeof(addr)); printf(" %s", inet_ntoa(addr)); } printf("\n"); }
static void idnsAddNameserver(const char *buf) { struct in_addr A; if (!safe_inet_addr(buf, &A)) { debug(78, 0) ("WARNING: rejecting '%s' as a name server, because it is not a numeric IP address\n", buf); return; } if (A.s_addr == 0) { debug(78, 0) ("WARNING: Squid does not accept 0.0.0.0 in DNS server specifications.\n"); debug(78, 0) ("Will be using 127.0.0.1 instead, assuming you meant that DNS is running on the same machine\n"); safe_inet_addr("127.0.0.1", &A); } if (nns == nns_alloc) { int oldalloc = nns_alloc; ns *oldptr = nameservers; if (nns_alloc == 0) nns_alloc = 2; else nns_alloc <<= 1; nameservers = xcalloc(nns_alloc, sizeof(*nameservers)); if (oldptr && oldalloc) xmemcpy(nameservers, oldptr, oldalloc * sizeof(*nameservers)); if (oldptr) safe_free(oldptr); } assert(nns < nns_alloc); nameservers[nns].S.sin_family = AF_INET; nameservers[nns].S.sin_port = htons(NS_DEFAULTPORT); nameservers[nns].S.sin_addr.s_addr = A.s_addr; debug(78, 3) ("idnsAddNameserver: Added nameserver #%d: %s\n", nns, inet_ntoa(nameservers[nns].S.sin_addr)); nns++; }
tlv * storeSwapMetaUnpack(const char *buf, int *hdr_len) { tlv *TLV = NULL; /* we'll return this */ tlv **T = &TLV; char type; int length; int buflen; int j = 0; assert(buf != NULL); assert(hdr_len != NULL); if (buf[j++] != (char) STORE_META_OK) return NULL; xmemcpy(&buflen, &buf[j], sizeof(int)); j += sizeof(int); /* * sanity check on 'buflen' value. It should be at least big * enough to hold one type and one length. */ if (buflen <= (sizeof(char) + sizeof(int))) return NULL; while (buflen - j >= (sizeof(char) + sizeof(int))) { type = buf[j++]; /* VOID is reserved, but allow some slack for new types.. */ if (type <= STORE_META_VOID || type > STORE_META_END + 10) { debug(20, 0) ("storeSwapMetaUnpack: bad type (%d)!\n", type); break; } xmemcpy(&length, &buf[j], sizeof(int)); if (length < 0 || length > (1 << 16)) { debug(20, 0) ("storeSwapMetaUnpack: insane length (%d)!\n", length); break; } j += sizeof(int); if (j + length > buflen) { debug(20, 0) ("storeSwapMetaUnpack: overflow!\n"); debug(20, 0) ("\ttype=%d, length=%d, buflen=%d, offset=%d\n", type, length, buflen, (int) j); break; } T = storeSwapTLVAdd(type, &buf[j], (size_t) length, T); j += length; } *hdr_len = buflen; return TLV; }
extern int regexec(regex_t* reg, const char* str, size_t nmatch, regmatch_t pmatch[], int posix_options) { int r, i, len; UChar* end; regmatch_t* pm; OnigOptionType options; options = ONIG_OPTION_POSIX_REGION; if ((posix_options & REG_NOTBOL) != 0) options |= ONIG_OPTION_NOTBOL; if ((posix_options & REG_NOTEOL) != 0) options |= ONIG_OPTION_NOTEOL; if (nmatch == 0 || (reg->comp_options & REG_NOSUB) != 0) { pm = (regmatch_t* )NULL; nmatch = 0; } else if ((int )nmatch < ONIG_C(reg)->num_mem + 1) { pm = (regmatch_t* )xmalloc(sizeof(regmatch_t) * (ONIG_C(reg)->num_mem + 1)); if (pm == NULL) return REG_ESPACE; } else { pm = pmatch; } ENC_STRING_LEN(ONIG_C(reg)->enc, str, len); end = (UChar* )(str + len); r = onig_search(ONIG_C(reg), (UChar* )str, end, (UChar* )str, end, (OnigRegion* )pm, options); if (r >= 0) { r = 0; /* Match */ if (pm != pmatch && pm != NULL) { xmemcpy(pmatch, pm, sizeof(regmatch_t) * nmatch); } } else if (r == ONIG_MISMATCH) { r = REG_NOMATCH; for (i = 0; i < (int )nmatch; i++) pmatch[i].rm_so = pmatch[i].rm_eo = ONIG_REGION_NOTPOS; } else { r = onig2posix_error_code(r); } if (pm != pmatch && pm != NULL) xfree(pm); #if 0 if (reg->re_nsub > nmatch - 1) reg->re_nsub = (nmatch <= 1 ? 0 : nmatch - 1); #endif return r; }
ssize_t stmemCopy(const mem_hdr * mem, squid_off_t offset, char *buf, size_t size) { mem_node *p = mem->head; squid_off_t t_off = mem->origin_offset; size_t bytes_to_go = size; char *ptr_to_buf = NULL; int bytes_from_this_packet = 0; int bytes_into_this_packet = 0; debug(19, 6) ("memCopy: offset %" PRINTF_OFF_T ": size %d\n", offset, (int) size); if (p == NULL) return 0; assert(size > 0); /* Seek our way into store */ while ((t_off + p->len) < offset) { t_off += p->len; if (!p->next) { debug(19, 1) ("memCopy: p->next == NULL\n"); return 0; } assert(p->next); p = p->next; } /* Start copying begining with this block until * we're satiated */ bytes_into_this_packet = offset - t_off; bytes_from_this_packet = XMIN(bytes_to_go, p->len - bytes_into_this_packet); xmemcpy(buf, p->data + bytes_into_this_packet, bytes_from_this_packet); bytes_to_go -= bytes_from_this_packet; ptr_to_buf = buf + bytes_from_this_packet; p = p->next; while (p && bytes_to_go > 0) { if (bytes_to_go > p->len) { xmemcpy(ptr_to_buf, p->data, p->len); ptr_to_buf += p->len; bytes_to_go -= p->len; } else { xmemcpy(ptr_to_buf, p->data, bytes_to_go); bytes_to_go -= bytes_to_go; } p = p->next; } return size - bytes_to_go; }
static CacheEntry * cacheEntryCreate(const storeSwapLogData * s) { CacheEntry *e = xcalloc(1, sizeof(CacheEntry)); assert(s); /* e->s = *s; */ xmemcpy(e->key_arr, s->key, MD5_DIGEST_CHARS); e->key = &e->key_arr[0]; return e; }
int ringbuf_pop_front(struct ringbuf *buf, void *dst, size_t n) { if (buf->bytes_filled < n) return -1; size_t read_pos = buf->write_pos >= buf->bytes_filled ? buf->write_pos - buf->bytes_filled : buf->capacity - (buf->bytes_filled - buf->write_pos); size_t n1 = min(buf->capacity - read_pos, n); xmemcpy(dst, buf->data + read_pos, n1); if (n > n1) xmemcpy((uint8_t *) dst + n1, buf->data, n - n1); buf->bytes_filled -= n; return 0; }
static void wccpAssignBuckets(void) { struct wccp_assign_bucket_t *wccp_assign_bucket; int wab_len; char *buckets; int buckets_per_cache; int loop; int bucket = 0; int *caches; int cache_len; char *buf; debug(80, 6) ("wccpAssignBuckets: Called\n"); number_caches = ntohl(wccp_i_see_you.number); if (number_caches > WCCP_ACTIVE_CACHES) number_caches = WCCP_ACTIVE_CACHES; wab_len = sizeof(struct wccp_assign_bucket_t); cache_len = WCCP_CACHE_LEN * number_caches; buf = xmalloc(wab_len + WCCP_BUCKETS + cache_len); wccp_assign_bucket = (struct wccp_assign_bucket_t *) buf; caches = (int *) (buf + wab_len); buckets = buf + wab_len + cache_len; memset(wccp_assign_bucket, '\0', sizeof(wccp_assign_bucket)); memset(buckets, 0xFF, WCCP_BUCKETS); buckets_per_cache = WCCP_BUCKETS / number_caches; for (loop = 0; loop < number_caches; loop++) { int i; xmemcpy(&caches[loop], &wccp_i_see_you.wccp_cache_entry[loop].ip_addr.s_addr, sizeof(*caches)); for (i = 0; i < buckets_per_cache; i++) { assert(bucket < WCCP_BUCKETS); buckets[bucket++] = loop; } } while (bucket < WCCP_BUCKETS) { buckets[bucket++] = number_caches - 1; } wccp_assign_bucket->type = htonl(WCCP_ASSIGN_BUCKET); wccp_assign_bucket->id = wccp_i_see_you.id; wccp_assign_bucket->number = wccp_i_see_you.number; send(theOutWccpConnection, buf, wab_len + WCCP_BUCKETS + cache_len, 0); change = 0; xfree(buf); }
void malloc_statistics(void (*func) (int, int, int, void *), void *data) { int i; for (i = 0; i <= DBG_SPLIT; i += DBG_GRAIN_SM) func(i, malloc_sizes[DBG_INDEX(i)], malloc_histo[DBG_INDEX(i)], data); i -= DBG_GRAIN_SM; for (i = i; i <= DBG_MAXSIZE; i += DBG_GRAIN) func(i, malloc_sizes[DBG_INDEX(i)], malloc_histo[DBG_INDEX(i)], data); xmemcpy(&malloc_histo, &malloc_sizes, sizeof(malloc_sizes)); }
CacheDigest * cacheDigestClone(const CacheDigest * cd) { CacheDigest *clone; assert(cd); clone = cacheDigestCreate(cd->capacity, cd->bits_per_entry); clone->count = cd->count; clone->del_count = cd->del_count; assert(cd->mask_size == clone->mask_size); xmemcpy(clone->mask, cd->mask, cd->mask_size); return clone; }
static void queue_write_msg(MESSAGE * m) { ((MESSAGE*)(m->tty_write_REQUEST_M))->write_RST = 0; int i; for (i=0;i<TTY_NUM;i++){ if (! wait_write_msgs[i].ext_flag) { xmemcpy(&(wait_write_msgs[i].m), m, sizeof(MESSAGE)); wait_write_msgs[i].ext_flag = 1; break; } } }
/* Append incoming data. */ void stmemAppend(mem_hdr * mem, const char *data, int len) { mem_node *p; int avail_len; int len_to_copy; debug(19, 6) ("memAppend: len %d\n", len); /* Does the last block still contain empty space? * If so, fill out the block before dropping into the * allocation loop */ if (mem->head && mem->tail && (mem->tail->len < SM_PAGE_SIZE)) { avail_len = SM_PAGE_SIZE - (mem->tail->len); len_to_copy = XMIN(avail_len, len); xmemcpy((mem->tail->data + mem->tail->len), data, len_to_copy); /* Adjust the ptr and len according to what was deposited in the page */ data += len_to_copy; len -= len_to_copy; mem->tail->len += len_to_copy; } while (len > 0) { len_to_copy = XMIN(len, SM_PAGE_SIZE); p = xcalloc(1, sizeof(mem_node)); p->next = NULL; p->len = len_to_copy; p->data = memAllocate(MEM_STMEM_BUF); store_mem_size += SM_PAGE_SIZE; xmemcpy(p->data, data, len_to_copy); if (!mem->head) { /* The chain is empty */ mem->head = mem->tail = p; } else { /* Append it to existing chain */ mem->tail->next = p; mem->tail = p; } len -= len_to_copy; data += len_to_copy; } }
static void icmpSendEcho(struct in_addr to, int opcode, const char *payload, int len) { static pingerEchoData pecho; if (payload && len == 0) len = strlen(payload); assert(len <= PINGER_PAYLOAD_SZ); pecho.to = to; pecho.opcode = (unsigned char) opcode; pecho.psize = len; xmemcpy(pecho.payload, payload, len); icmpSend(&pecho, sizeof(pingerEchoData) - PINGER_PAYLOAD_SZ + len); }
static void icmpHandleSourcePing(const struct sockaddr_in *from, const char *buf) { const cache_key *key; icp_common_t header; const char *url; xmemcpy(&header, buf, sizeof(icp_common_t)); url = buf + sizeof(icp_common_t); key = icpGetCacheKey(url, (int) header.reqnum); debug(37, 3) ("icmpHandleSourcePing: from %s, key '%s'\n", inet_ntoa(from->sin_addr), storeKeyText(key)); /* call neighborsUdpAck even if ping_status != PING_WAITING */ neighborsUdpAck(key, &header, from); }
struct env *env_open(const char *home, uint32_t flags) { LOG; struct env *e; e = xcalloc(1, sizeof(*e)); e->flags = flags; /* tree */ e->inner_node_fanout = 16; e->inner_default_node_size = 4 << 20; /* 4MB */ e->leaf_default_node_size = 4 << 20; /* 4MB */ e->leaf_default_basement_size = 128 << 10; /* 128KB */ /* cache */ e->cache_limits_bytes = 1024 << 20; e->cache_high_watermark = 80; /* 80% */ e->cache_flush_period_ms = 100; /* 0.1s */ e->cache_checkpoint_period_ms = 600000; /* 60s */ /* IO */ e->use_directio = 1; e->redo_path = "./dbbench"; e->enable_redo_log = 1; if (!home) home = "."; e->dir = xcalloc(1, strlen(home) + 1); xmemcpy(e->dir, (void*)home, strlen(home)); ness_check_dir(e->dir); /* compress */ e->compress_method = NESS_SNAPPY_METHOD; /* callback */ e->bt_compare_func = bt_compare_func_builtin; /* internal */ e->cache = cache_new(e); /* e->cache->cf_first->hdr->blocksize */ nassert(e->cache); e->txnmgr = txnmgr_new(); nassert(e->txnmgr); e->status = status_new(); nassert(e->status); return e; }
static void cacheDigestHashKey(const CacheDigest * cd, const cache_key * key) { const unsigned int bit_count = cd->mask_size * 8; unsigned int tmp_keys[4]; /* we must memcpy to ensure alignment */ xmemcpy(tmp_keys, key, sizeof(tmp_keys)); hashed_keys[0] = htonl(tmp_keys[0]) % bit_count; hashed_keys[1] = htonl(tmp_keys[1]) % bit_count; hashed_keys[2] = htonl(tmp_keys[2]) % bit_count; hashed_keys[3] = htonl(tmp_keys[3]) % bit_count; debug(70, 9) ("cacheDigestHashKey: %s -(%d)-> %d %d %d %d\n", storeKeyText(key), bit_count, hashed_keys[0], hashed_keys[1], hashed_keys[2], hashed_keys[3]); }
int main(int argc, char *argv[]) { char buf[RECV_BUF_SIZE]; struct sockaddr_in R; int len; struct hostent *hp = NULL; char logfile[BUFSIZ]; char ip[4]; for (len = 0; len < 32; len++) { signal(len, sig_handle); } if (argc > 1) strcpy(logfile, argv[1]); else strcpy(logfile, "/tmp/recv-announce.log"); close(1); if (open(logfile, O_WRONLY | O_CREAT | O_APPEND, 0660) < 0) { perror(logfile); exit(1); } close(2); dup(1); for (;;) { memset(buf, '\0', RECV_BUF_SIZE); memset(&R, '\0', len = sizeof(R)); if (recvfrom(0, buf, RECV_BUF_SIZE, 0, &R, &len) < 0) { perror("recv"); exit(2); } xmemcpy(ip, &R.sin_addr.s_addr, 4); hp = gethostbyaddr(ip, 4, AF_INET); printf("==============================================================================\n"); printf("Received from %s [%s]\n", inet_ntoa(R.sin_addr), (hp && hp->h_name) ? hp->h_name : "Unknown"); fputs(buf, stdout); fflush(stdout); } return 0; }
static void storeDiskdReadDone(diomsg * M) { storeIOState *sio = M->callback_data; STRCB *callback = sio->read.callback; SwapDir *sd = INDEXSD(sio->swap_dirn); diskdstate_t *diskdstate = sio->fsstate; diskdinfo_t *diskdinfo = sd->fsdata; void *their_data = sio->read.callback_data; char *their_buf = diskdstate->read_buf; char *sbuf; size_t len; int valid; statCounter.syscalls.disk.reads++; diskdstate->flags.reading = 0; if (diskdstate->flags.close_request) { debug(79, 2) ("storeDiskReadDone: closing, so ignore!\n"); return; } valid = cbdataValid(sio->read.callback_data); cbdataUnlock(sio->read.callback_data); debug(79, 3) ("storeDiskdReadDone: dirno %d, fileno %08x status %d\n", sio->swap_dirn, sio->swap_filen, M->status); if (M->status < 0) { diskd_stats.read.fail++; storeDiskdIOCallback(sio, DISK_ERROR); return; } diskd_stats.read.success++; sbuf = diskdinfo->shm.buf + M->shm_offset; len = M->status; sio->offset += len; assert(callback); assert(their_data); sio->read.callback = NULL; sio->read.callback_data = NULL; if (valid) { assert(!diskdstate->flags.close_request); /* * Only copy the data if the callback is still valid, * if it isn't valid then the request should have been * aborted. * -- adrian */ xmemcpy(their_buf, sbuf, len); /* yucky copy */ callback(their_data, their_buf, len); } }