本文整理汇总了C++中MEM函数的典型用法代码示例。如果您正苦于以下问题:C++ MEM函数的具体用法?C++ MEM怎么用?C++ MEM使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了MEM函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C++代码示例。
示例1: mod_bootstrap
static int mod_bootstrap(void *instance, CONF_SECTION *conf)
{
rlm_unbound_t *inst = instance;
inst->name = cf_section_name2(conf);
if (!inst->name) inst->name = cf_section_name1(conf);
if (inst->timeout > 10000) {
cf_log_err(conf, "timeout must be 0 to 10000");
return -1;
}
MEM(inst->xlat_a_name = talloc_typed_asprintf(inst, "%s-a", inst->name));
MEM(inst->xlat_aaaa_name = talloc_typed_asprintf(inst, "%s-aaaa", inst->name));
MEM(inst->xlat_ptr_name = talloc_typed_asprintf(inst, "%s-ptr", inst->name));
if (xlat_register(inst, inst->xlat_a_name, xlat_a, NULL, NULL, 0, XLAT_DEFAULT_BUF_LEN, false) ||
xlat_register(inst, inst->xlat_aaaa_name, xlat_aaaa, NULL, NULL, 0, XLAT_DEFAULT_BUF_LEN, false) ||
xlat_register(inst, inst->xlat_ptr_name, xlat_ptr, NULL, NULL, 0, XLAT_DEFAULT_BUF_LEN, false)) {
cf_log_err(conf, "Failed registering xlats");
return -1;
}
return 0;
}
开发者ID:geaaru,项目名称:freeradius-server,代码行数:25,代码来源:rlm_unbound.c
示例2: mod_thread_instantiate
/** Create thread-specific connections and buffers
*
* @param[in] conf section containing the configuration of this module instance.
* @param[in] instance of rlm_logtee_t.
* @param[in] el The event list serviced by this thread.
* @param[in] thread specific data.
* @return
* - 0 on success.
* - -1 on failure.
*/
static int mod_thread_instantiate(UNUSED CONF_SECTION const *conf, void *instance, fr_event_list_t *el, void *thread)
{
rlm_logtee_t *inst = talloc_get_type_abort(instance, rlm_logtee_t);
rlm_logtee_thread_t *t = talloc_get_type_abort(thread, rlm_logtee_thread_t);
MEM(t->fring = fr_fring_alloc(t, inst->buffer_depth, false));
t->inst = inst;
t->el = el;
/*
* Pre-allocate temporary attributes
*/
MEM(t->msg_pool = talloc_pool(t, 1024));
MEM(t->msg = fr_pair_afrom_da(t->msg_pool, attr_log_message));
MEM(t->type = fr_pair_afrom_da(t, attr_log_type));
MEM(t->lvl = fr_pair_afrom_da(t, attr_log_level));
/*
* This opens the outbound connection
*/
t->conn = fr_connection_alloc(t, el, &inst->connection_timeout, &inst->reconnection_delay,
_logtee_conn_init, _logtee_conn_open, _logtee_conn_close,
inst->name, t);
if (t->conn == NULL) return -1;
fr_connection_signal_init(t->conn);
return 0;
}
开发者ID:FreeRADIUS,项目名称:freeradius-server,代码行数:41,代码来源:rlm_logtee.c
示例3: solve
int solve(){
//Init
MEM(lx, 0); MEM(ly, 0);
MEM(left, 0);
for (int i = 1; i <= sv; i ++)
for (int j = 1; j <= tv; j ++)
lx[i] = max(lx[i], w[i][j]);
//Main
for (int i = 1; i <= sv; i ++){
for (int j = 1; j <= tv; j ++) slack[j] = oo;
while(1){
MEM(S, false); MEM(T, false);
if (cross_path(i)){
break;
}
else{
int d = oo;
for (int j = 1; j <= tv; j ++)
if (!T[j]) d = min(d, slack[j]);
for (int j = 1; j <= sv; j ++)
if (S[j]) lx[j] -= d;
for (int j = 1; j <= tv; j ++){
if (T[j]) ly[j] += d;
else slack[j] -= d;
//匈牙利树中T集点ly不变,S集点lx减小,更新slack值
}
}
}
}
int res = 0;
for(int i = 1; i <= sv; i ++) res += lx[i];
for(int i = 1; i <= tv; i ++) res += ly[i];
return res;
}
开发者ID:lzql658,项目名称:ACM_Algorithm_Templates,代码行数:34,代码来源:KM.cpp
示例4: mrc_dump_process
void mrc_dump_process()
{
/* generate instruction into uncacheable memory (else we would have to flush I and D caches) */
void *alloc_buf = malloc(32);
void *func_buf = UNCACHEABLE(alloc_buf);
unsigned int addr_func = (unsigned int)UNCACHEABLE(func_buf);
unsigned int (*func)() = (unsigned int (*)())addr_func;
/* build MRC instruction */
unsigned int instr = 0xEE100010;
instr |= (mrc_op1<<21);
instr |= (mrc_crn<<16);
instr |= (0<<12);
instr |= (mrc_cp<<8);
instr |= (mrc_op2<<5);
instr |= mrc_crm;
/* write along with RET */
MEM(addr_func) = instr;
MEM(addr_func + 4) = 0xE1A0F00E;
/* call generated code */
mrc_value = func();
free(alloc_buf);
}
开发者ID:HulaSamsquanch,项目名称:1100d_lantern,代码行数:27,代码来源:mrc_dump.c
示例5: MEM
void NameList::grow()
{
int newmax=max+GRANULARITY;
names=(char**)realloc(names, newmax*sizeof(char*)); MEM(names);
touched=(bool*)realloc(touched, newmax*sizeof(bool)); MEM(touched);
max=newmax;
}
开发者ID:frarees,项目名称:rvtmod,代码行数:7,代码来源:namelist.cpp
示例6: ceil
void LookupGrid::doneSizing(void)
{
rvfloat size_x1, size_x2, size_z1, size_z2;
int i;
size_x1 = (xhi-xlo)/60.0; size_z1= (zhi-zlo)/60.0;
size_x2 = size_z2 = 500.0;
data.raster_size=rint((size_x1+ size_x2+ size_z1+ size_z2) / 4.0);
data.x0 = xlo;
data.z0 = zlo;
data.x_size = ceil((xhi-xlo)/data.raster_size);
data.z_size = ceil((zhi-zlo)/data.raster_size);
xsz=(int)data.x_size; zsz=(int)data.z_size;
ichains=new IndexChain*[zsz*xsz]; MEM(ichains);
for(i=0;i<zsz*xsz;i++)
{
ichains[i]=new IndexChain; MEM(ichains[i]);
};
lprintf(3,"LookupGrid: bounds are X(%g..%g), Z(%g..%g)\n",xlo,xhi,zlo,zhi);
lprintf(3,"LookupGrid: created %dx%d grid\n",xsz,zsz);
lprintf(3,"LookupGrid: origin (%g,%g), raster_size %g\n",data.x0,data.z0,data.raster_size);
}
开发者ID:frarees,项目名称:rvtmod,代码行数:28,代码来源:lookup.cpp
示例7: main
int main(int argc, char **argv)
{
int i;
unsigned long t;
setvbuf(stdout, (char *) NULL, _IOLBF, 0);
if (argc != 2 && argc != 3)
{
fprintf(stderr, "syntax: %s input_file [-r]\n", argv[0]);
return 1;
}
if (*argv[1] == '-')
{
fprintf(stderr, "syntax: %s input_file [-r]\n", argv[0]);
return 1;
}
if ((FP = fopen(argv[1], "r")) == NULL)
{
fprintf(stderr, "%s: cannot open input file %s\n", argv[0], argv[1]);
return 1;
}
if (argc == 3)
{
if (strcmp(argv[2], "-r") == 0)
{
Redir = (char *) RedirPrefix;
fprintf(stdout, "%s\n", argv[0]);
}
else
{
fprintf(stderr, "syntax: %s input_file [-r]\n", argv[0]);
return 1;
}
}
memset(Mem, 0, MEMSIZE * sizeof(unsigned));
for (i = PCINIT; !feof(FP); i += 4)
{
if (fgets(Buf, BUFSIZE, FP) == NULL)
{
if (feof(FP))
break;
fprintf(stderr, "%s: file %s reading error\n", argv[0], argv[1]);
return 1;
}
if (sscanf(Buf, "%lx", &t) != 1)
{
fprintf(stderr, "%s: file %s error in line %d, continue...\n",
argv[0], argv[1], i - PCINIT + 1);
MEM(i) = 0;
}
else
{
MEM(i) = strtoul(Buf, (char **) NULL, 16);
}
}
Loop();
fclose(FP);
return 0;
}
开发者ID:kaveman1105,项目名称:CDA-project,代码行数:59,代码来源:spimcore.c
示例8: uemd_em_init
void uemd_em_init(void)
{
MEM(0x2003c050)=0x9; //DDR PHY ODT ON
ddr_init(DMC0_APB_BASE);
MEM(0x2003c064)=0x9; //DDR PHY ODT ON
ddr_init(DMC1_APB_BASE);
}
开发者ID:RC-MODULE,项目名称:mboot,代码行数:8,代码来源:uemd_ddr.c
示例9: qfio_read
void qfio_read(char* buf, int num) // read "num" bytes from QEMU FIO buffer, into "buf"
{
MEM(REG_FIO_BUFFER_SEEK) = 0;
for (int i = 0; i < num; i++)
{
buf[i] = MEM(REG_FIO_BUFFER);
}
}
开发者ID:HulaSamsquanch,项目名称:1100d_lantern,代码行数:9,代码来源:qemu-helper.c
示例10: MEM
/*
* Convert a buffer to a CSV entry
*/
static rlm_csv_entry_t *file2csv(CONF_SECTION *conf, rlm_csv_t *inst, int lineno, char *buffer)
{
rlm_csv_entry_t *e;
int i;
char *p, *q;
MEM(e = (rlm_csv_entry_t *)talloc_zero_array(inst->tree, uint8_t,
sizeof(*e) + inst->used_fields + sizeof(e->data[0])));
talloc_set_type(e, rlm_csv_entry_t);
for (p = buffer, i = 0; p != NULL; p = q, i++) {
if (!buf2entry(inst, p, &q)) {
cf_log_err(conf, "Malformed entry in file %s line %d", inst->filename, lineno);
return NULL;
}
if (q) *(q++) = '\0';
if (i >= inst->num_fields) {
cf_log_err(conf, "Too many fields at file %s line %d", inst->filename, lineno);
return NULL;
}
/*
* This is the key field.
*/
if (i == inst->key_field) {
e->key = talloc_typed_strdup(e, p);
continue;
}
/*
* This field is unused. Ignore it.
*/
if (inst->field_offsets[i] < 0) continue;
MEM(e->data[inst->field_offsets[i]] = talloc_typed_strdup(e, p));
}
if (i < inst->num_fields) {
cf_log_err(conf, "Too few fields at file %s line %d (%d < %d)", inst->filename, lineno, i, inst->num_fields);
return NULL;
}
/*
* FIXME: Allow duplicate keys later.
*/
if (!rbtree_insert(inst->tree, e)) {
cf_log_err(conf, "Failed inserting entry for filename %s line %d: duplicate entry",
inst->filename, lineno);
return NULL;
}
return e;
}
开发者ID:mcnewton,项目名称:freeradius-server,代码行数:58,代码来源:rlm_csv.c
示例11: debug_console_getc
int debug_console_getc(void)
{
char c;
// Wait until the serial RX buffer is not empty
while (MEM(SERIAL_BASE + SERIAL_FLAG_REGISTER) & (SERIAL_RX_BUFFER_EMPTY))
;
c = 0xFF & MEM(SERIAL_BASE);
return c;
}
开发者ID:animotron,项目名称:animos,代码行数:11,代码来源:debug_console.c
示例12: debug_console_getc
int debug_console_getc(void)
{
char c;
// Wait until the serial RX buffer is not empty
while(!MEM(DEBUG_CONSOLE_SERIAL_BASE + SERIAL_FLAG_REGISTER) & SERIAL_RX_READY)
;
c = 0xFF & MEM(DEBUG_CONSOLE_SERIAL_BASE);
return c;
}
开发者ID:NoSuchProcess,项目名称:phantomuserland,代码行数:11,代码来源:debug_console.c
示例13: compute_keys
int compute_keys(UNUSED REQUEST *request, pwd_session_t *session, uint8_t *peer_confirm, uint8_t *msk, uint8_t *emsk)
{
HMAC_CTX *hmac_ctx;
uint8_t mk[SHA256_DIGEST_LENGTH], *cruft;
uint8_t session_id[SHA256_DIGEST_LENGTH + 1];
uint8_t msk_emsk[128]; /* 64 each */
int offset;
MEM(cruft = talloc_array(session, uint8_t, BN_num_bytes(session->prime)));
MEM(hmac_ctx = HMAC_CTX_new());
/*
* first compute the session-id = TypeCode | H(ciphersuite | scal_p |
* scal_s)
*/
session_id[0] = FR_EAP_METHOD_PWD;
HMAC_Init_ex(hmac_ctx, allzero, SHA256_DIGEST_LENGTH, EVP_sha256(), NULL);
HMAC_Update(hmac_ctx, (uint8_t *)&session->ciphersuite, sizeof(session->ciphersuite));
offset = BN_num_bytes(session->order) - BN_num_bytes(session->peer_scalar);
memset(cruft, 0, BN_num_bytes(session->prime));
BN_bn2bin(session->peer_scalar, cruft + offset);
HMAC_Update(hmac_ctx, cruft, BN_num_bytes(session->order));
offset = BN_num_bytes(session->order) - BN_num_bytes(session->my_scalar);
memset(cruft, 0, BN_num_bytes(session->prime));
BN_bn2bin(session->my_scalar, cruft + offset);
HMAC_Update(hmac_ctx, cruft, BN_num_bytes(session->order));
pwd_hmac_final(hmac_ctx, (uint8_t *)&session_id[1]);
/* then compute MK = H(k | commit-peer | commit-server) */
HMAC_Init_ex(hmac_ctx, allzero, SHA256_DIGEST_LENGTH, EVP_sha256(), NULL);
memset(cruft, 0, BN_num_bytes(session->prime));
offset = BN_num_bytes(session->prime) - BN_num_bytes(session->k);
BN_bn2bin(session->k, cruft + offset);
HMAC_Update(hmac_ctx, cruft, BN_num_bytes(session->prime));
HMAC_Update(hmac_ctx, peer_confirm, SHA256_DIGEST_LENGTH);
HMAC_Update(hmac_ctx, session->my_confirm, SHA256_DIGEST_LENGTH);
pwd_hmac_final(hmac_ctx, mk);
/* stretch the mk with the session-id to get MSK | EMSK */
eap_pwd_kdf(mk, SHA256_DIGEST_LENGTH, (char const *)session_id,
SHA256_DIGEST_LENGTH + 1, msk_emsk, 1024); /* it's bits, ((64 + 64) * 8) */
memcpy(msk, msk_emsk, 64);
memcpy(emsk, msk_emsk + 64, 64);
HMAC_CTX_free(hmac_ctx);
talloc_free(cruft);
return 0;
}
开发者ID:FreeRADIUS,项目名称:freeradius-server,代码行数:53,代码来源:eap_pwd.c
示例14: prefix_suffix_cmp
/*
* Compare prefix/suffix.
*
* If they compare:
* - if FR_STRIP_USER_NAME is present in check_list,
* strip the username of prefix/suffix.
* - if FR_STRIP_USER_NAME is not present in check_list,
* add a FR_STRIPPED_USER_NAME to the request.
*/
static int prefix_suffix_cmp(UNUSED void *instance,
REQUEST *request,
VALUE_PAIR *req,
VALUE_PAIR *check,
VALUE_PAIR *check_list,
UNUSED VALUE_PAIR **reply_list)
{
VALUE_PAIR *vp;
char const *name;
char rest[FR_MAX_STRING_LEN];
int len, namelen;
int ret = -1;
if (!request || !request->username) return -1;
VP_VERIFY(check);
name = request->username->vp_strvalue;
RDEBUG3("Comparing name \"%s\" and check value \"%s\"", name, check->vp_strvalue);
len = strlen(check->vp_strvalue);
if (check->da == attr_prefix) {
ret = strncmp(name, check->vp_strvalue, len);
if (ret == 0)
strlcpy(rest, name + len, sizeof(rest));
} else if (check->da == attr_suffix) {
namelen = strlen(name);
if (namelen >= len) {
ret = strcmp(name + namelen - len, check->vp_strvalue);
if (ret == 0) strlcpy(rest, name, namelen - len + 1);
}
}
if (ret != 0) return ret;
/*
* If Strip-User-Name == No, then don't do any more.
*/
vp = fr_pair_find_by_da(check_list, attr_strip_user_name, TAG_ANY);
if (vp && !vp->vp_uint32) return ret;
/*
* See where to put the stripped user name.
*/
vp = fr_pair_find_by_da(check_list, attr_stripped_user_name, TAG_ANY);
if (!vp) {
/*
* If "request" is NULL, then the memory will be
* lost!
*/
MEM(vp = fr_pair_afrom_da(request->packet, attr_stripped_user_name));
fr_pair_add(&req, vp);
request->username = vp;
}
fr_pair_value_strcpy(vp, rest);
return ret;
}
开发者ID:zi0r,项目名称:freeradius-server,代码行数:69,代码来源:paircmp.c
示例15: main
int main(int argc, char **argv)
{
AppOptions appopt;
appopt.cmd=CmdVis;
appopt.parse(argc, argv);
msglevel=appopt.msglevel;
appopt.welcome();
if(appopt.listsyntax_only)
{
dump_visfile_syntax();
}
else if(appopt.listobj_only)
{
ASEParser p(appopt.ase_name);
p.parse(NULL, NULL, NULL);
}
else
{
ASEMeshList *meshes=new ASEMeshList(); MEM(meshes);
ASEParser p(appopt.ase_name);
p.parse(meshes, NULL, appopt.names);
BoxList *b=meshes->createBoxes(appopt.list_name, /*vis=*/true);
b->write_vis(appopt.out_name, appopt.safety_dist, 0.0);
delete b;
appopt.warn_untouched();
delete meshes;
}
return 0;
}
开发者ID:frarees,项目名称:rvtmod,代码行数:31,代码来源:ase2vis.cpp
示例16: vlog_module_failure_msg
/** Add a module failure message VALUE_PAIR to the request
*
* @param[in] request The current request.
* @param[in] msg with printf style substitution tokens.
* @param[in] ap Substitution arguments.
*/
void vlog_module_failure_msg(REQUEST *request, char const *msg, va_list ap)
{
char *p;
VALUE_PAIR *vp;
va_list aq;
if (!msg || !request || !request->packet) return;
rad_assert(attr_module_failure_message);
/*
* If we don't copy the original ap we get a segfault from vasprintf. This is apparently
* due to ap sometimes being implemented with a stack offset which is invalidated if
* ap is passed into another function. See here:
* http://julipedia.meroh.net/2011/09/using-vacopy-to-safely-pass-ap.html
*
* I don't buy that explanation, but doing a va_copy here does prevent SEGVs seen when
* running unit tests which generate errors under CI.
*/
va_copy(aq, ap);
p = fr_vasprintf(request, msg, aq);
va_end(aq);
MEM(pair_add_request(&vp, attr_module_failure_message) >= 0);
if (request->module && (request->module[0] != '\0')) {
fr_pair_value_snprintf(vp, "%s: %s", request->module, p);
} else {
fr_pair_value_snprintf(vp, "%s", p);
}
talloc_free(p);
}
开发者ID:mcnewton,项目名称:freeradius-server,代码行数:37,代码来源:log.c
示例17: arp_socket_decode
static int arp_socket_decode(UNUSED rad_listen_t *listener, REQUEST *request)
{
int i;
uint8_t const *p = request->packet->data, *end = p + request->packet->data_len;
fr_cursor_t cursor;
fr_cursor_init(&cursor, &request->packet->vps);
for (i = 0; header_names[i].name != NULL; i++) {
ssize_t ret;
size_t len;
fr_dict_attr_t const *da;
VALUE_PAIR *vp = NULL;
len = header_names[i].len;
if (!fr_cond_assert((size_t)(end - p) < len)) return -1; /* Should have been detected in socket_recv */
da = fr_dict_attr_by_name(dict_arp, header_names[i].name);
if (!da) return 0;
MEM(vp = fr_pair_afrom_da(request->packet, da));
ret = fr_value_box_from_network(vp, &vp->data, da->type, da, p, len, true);
if (ret <= 0) {
fr_pair_to_unknown(vp);
fr_pair_value_memcpy(vp, p, len);
}
DEBUG2("&%pP", vp);
fr_cursor_insert(&cursor, vp);
}
return 0;
}
开发者ID:zi0r,项目名称:freeradius-server,代码行数:34,代码来源:proto_arp.c
示例18: regex_request_to_sub_named
/** Extract a named subcapture value from the request
*
* @note This is the PCRE variant of the function.
*
* @param[in] ctx To allocate subcapture buffer in.
* @param[out] out Where to write the subcapture string.
* @param[in] request to extract.
* @param[in] name of subcapture.
* @return
* - 0 on success.
* - -1 on notfound.
*/
int regex_request_to_sub_named(TALLOC_CTX *ctx, char **out, REQUEST *request, char const *name)
{
fr_regcapture_t *rc;
char const *p;
int ret;
rc = request_data_reference(request, request, REQUEST_DATA_REGEX);
if (!rc) {
RDEBUG4("No subcapture data found");
*out = NULL;
return 1;
}
ret = pcre_get_named_substring(rc->preg->compiled, rc->regmatch->subject,
(int *)rc->regmatch->match_data, (int)rc->regmatch->used, name, &p);
switch (ret) {
case PCRE_ERROR_NOMEMORY:
MEM(NULL);
/*
* We can't really fall through, but GCC 7.3 is
* too stupid to realise that we can never get
* here despite _fr_exit_now being marked as
* NEVER_RETURNS.
*
* If we did anything else, compilers and static
* analysis tools would probably complain about
* code that could never be executed *sigh*.
*/
/* FALL-THROUGH */
/*
* Not finding a substring is fine
*/
case PCRE_ERROR_NOSUBSTRING:
RDEBUG4("No named capture group \"%s\"", name);
*out = NULL;
return -1;
default:
if (ret < 0) {
*out = NULL;
return -1;
}
/*
* Check libpcre really is using our overloaded
* memory allocation and freeing talloc wrappers.
*/
talloc_set_type(p, char);
talloc_steal(ctx, p);
RDEBUG4("Found \"%s\": %pV (%zu)", name,
fr_box_strvalue_buffer(p), talloc_array_length(p) - 1);
memcpy(out, &p, sizeof(*out));
break;
}
return 0;
}
开发者ID:FreeRADIUS,项目名称:freeradius-server,代码行数:72,代码来源:regex.c
示例19: vmodule_failure_msg
/** Add a module failure message VALUE_PAIR to the request
*/
void vmodule_failure_msg(REQUEST *request, char const *fmt, va_list ap)
{
char *p;
VALUE_PAIR *vp;
va_list aq;
if (!fmt || !request->packet) {
return;
}
/*
* If we don't copy the original ap we get a segfault from vasprintf. This is apparently
* due to ap sometimes being implemented with a stack offset which is invalidated if
* ap is passed into another function. See here:
* http://julipedia.meroh.net/2011/09/using-vacopy-to-safely-pass-ap.html
*
* I don't buy that explanation, but doing a va_copy here does prevent SEGVs seen when
* running unit tests which generate errors under CI.
*/
va_copy(aq, ap);
p = talloc_vasprintf(request, fmt, aq);
va_end(aq);
MEM(vp = pairmake_packet("Module-Failure-Message", NULL, T_OP_ADD));
if (request->module && (request->module[0] != '\0')) {
pairsprintf(vp, "%s: %s", request->module, p);
} else {
pairsprintf(vp, "%s", p);
}
talloc_free(p);
}
开发者ID:pawelbien,项目名称:freeradius-server,代码行数:33,代码来源:valuepair.c
示例20: fr_network_directory_callback
/** Handle a network control message callback for a new "watch directory"
*
* @param[in] ctx the network
* @param[in] data the message
* @param[in] data_size size of the data
* @param[in] now the current time
*/
static void fr_network_directory_callback(void *ctx, void const *data, size_t data_size, UNUSED fr_time_t now)
{
int num_messages;
fr_network_t *nr = ctx;
fr_network_socket_t *s;
fr_app_io_t const *app_io;
fr_event_vnode_func_t funcs = { .extend = fr_network_vnode_extend };
rad_assert(data_size == sizeof(s->listen));
if (data_size != sizeof(s->listen)) return;
s = talloc_zero(nr, fr_network_socket_t);
rad_assert(s != NULL);
s->nr = nr;
memcpy(&s->listen, data, sizeof(s->listen));
s->number = nr->num_sockets++;
MEM(s->waiting = fr_heap_create(s, waiting_cmp, fr_channel_data_t, channel.heap_id));
talloc_set_destructor(s, _network_socket_free);
/*
* Allocate the ring buffer for messages and packets.
*/
num_messages = s->listen->num_messages;
if (num_messages < 8) num_messages = 8;
s->ms = fr_message_set_create(s, num_messages,
sizeof(fr_channel_data_t),
s->listen->default_message_size * s->listen->num_messages);
if (!s->ms) {
fr_log(nr->log, L_ERR, "Failed creating message buffers for directory IO: %s", fr_strerror());
talloc_free(s);
return;
}
app_io = s->listen->app_io;
if (app_io->event_list_set) app_io->event_list_set(s->listen->app_io_instance, nr->el, nr);
rad_assert(app_io->fd);
s->fd = app_io->fd(s->listen->app_io_instance);
s->filter = FR_EVENT_FILTER_VNODE;
if (fr_event_filter_insert(nr, nr->el, s->fd, s->filter,
&funcs,
app_io->error ? fr_network_error : NULL,
s) < 0) {
PERROR("Failed adding new socket to event loop");
talloc_free(s);
return;
}
(void) rbtree_insert(nr->sockets, s);
(void) rbtree_insert(nr->sockets_by_num, s);
DEBUG3("Using new socket with FD %d", s->fd);
}
开发者ID:bt4,项目名称:freeradius-server,代码行数:67,代码来源:network.c
注:本文中的MEM函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论