int network_client_send_slab(struct network_client_s *client, struct data_slab_s *ds) { EXTRA_ASSERT(client != NULL); EXTRA_ASSERT(ds != NULL); client->time.evt_out = network_server_bogonow(client->server); if (!_client_ready_for_output(client)) { register int type = ds->type; GRID_DEBUG("fd=%d Discarding data, output closed", client->fd); data_slab_free(ds); return MACRO_COND(type == STYPE_EOF, 0, -1); } /* Try to send the slab now, if allowed */ if (!_client_has_pending_output(client)) { if (!data_slab_send(ds, client->fd)) { if (errno != EAGAIN) { data_slab_free(ds); return -1; } } } /* manage what remains */ if (!data_slab_has_data(ds)) data_slab_free(ds); else data_slab_sequence_append(&(client->output), ds); return 0; }
static struct meta1_service_url_s * __poll_services(struct meta1_backend_s *m1, guint replicas, struct compound_type_s *ct, guint seq, struct meta1_service_url_s **used, GError **err) { struct grid_lb_iterator_s *iter = NULL; struct service_info_s **siv = NULL; GRID_DEBUG("Polling %u [%s]", replicas, ct->fulltype); if (!(*err = _get_iterator(m1, ct, &iter))) { struct lb_next_opt_ext_s opt; memset(&opt, 0, sizeof(opt)); opt.req.distance = MACRO_COND(replicas>1,1,0); opt.req.max = replicas; opt.req.duplicates = FALSE; opt.req.stgclass = NULL; opt.req.strict_stgclass = TRUE; opt.srv_forbidden = __srvinfo_from_m1srvurl(m1->lb, ct->baretype, used); if (ct->req.k && !strcmp(ct->req.k, NAME_TAGNAME_USER_IS_SERVICE)) { gchar *srvurl = g_strdup_printf("1||%s|", ct->req.v); struct meta1_service_url_s *inplace[2] = { meta1_unpack_url(srvurl), NULL }; /* If ct->req.v is not an addr, srv_inplace will contain NULL */ opt.srv_inplace = __srvinfo_from_m1srvurl(m1->lb, NULL, inplace); opt.req.distance = 1; meta1_service_url_clean(inplace[0]); g_free(srvurl); } else { opt.filter.hook = _filter_tag; opt.filter.data = ct; } if (!grid_lb_iterator_next_set2(iter, &siv, &opt)) { EXTRA_ASSERT(siv == NULL); *err = NEWERROR(CODE_POLICY_NOT_SATISFIABLE, "No service available"); } grid_lb_iterator_clean(iter); iter = NULL; g_slist_free_full(opt.srv_forbidden, (GDestroyNotify)service_info_clean); g_slist_free_full(opt.srv_inplace, (GDestroyNotify)service_info_clean); } if(NULL != *err) return NULL; struct meta1_service_url_s *m1u = _siv_to_url (siv); service_info_cleanv(siv, FALSE); siv = NULL; g_strlcpy(m1u->srvtype, ct->type, sizeof(m1u->srvtype)); m1u->seq = seq; return m1u; }
int rain_repair_and_get_raw_data(uint8_t **data, uint8_t **coding, size_t rawlength, unsigned int k, unsigned int m, const char* algo) { struct rain_encoding_s enc; if (!encoding_prepare(&enc, algo, k, m, rawlength)) return EXIT_FAILURE; int rc = rain_rehydrate(data, coding, &enc, &env_DEFAULT); return MACRO_COND(rc!=0,EXIT_SUCCESS,EXIT_FAILURE); }
static void _manage_client_event(struct network_server_s *srv, struct network_client_s *clt, register int ev0, struct timespec *now) { _client_remove_from_monitored(srv, clt); if (!srv->flag_continue) clt->transport.waiting_for_close = TRUE; ev0 = MACRO_COND(ev0 & EPOLLIN, CLT_READ, 0) | MACRO_COND(ev0 & EPOLLOUT, CLT_WRITE, 0) | MACRO_COND(ev0 & (EPOLLERR|EPOLLHUP|EPOLLRDHUP), CLT_ERROR, 0); clt->events = MACRO_COND(!ev0, CLT_ERROR, ev0); if (ev0 & EPOLLIN) memcpy(&clt->time.evt_in, now, sizeof(struct timespec)); if (clt->events & CLT_ERROR) ARM_CLIENT(srv, clt, EPOLL_CTL_DEL); g_async_queue_push(srv->queue_events, clt); }
static void _task_register(gpointer p) { if (PSRV(p)->flag_noregister) return; /* Computes the avg requests rate/time */ time_t now = oio_ext_monotonic_time () / G_TIME_SPAN_SECOND; grid_single_rrd_push (PSRV(p)->gsr_reqcounter, now, network_server_stat_getone(PSRV(p)->server, g_quark_from_static_string(OIO_STAT_PREFIX_REQ))); grid_single_rrd_push (PSRV(p)->gsr_reqtime, now, network_server_stat_getone(PSRV(p)->server, g_quark_from_static_string(OIO_STAT_PREFIX_TIME))); guint64 avg_counter = grid_single_rrd_get_delta(PSRV(p)->gsr_reqcounter, now, 4); guint64 avg_time = grid_single_rrd_get_delta(PSRV(p)->gsr_reqtime, now, 4); avg_counter = MACRO_COND(avg_counter != 0, avg_counter, 1); avg_time = MACRO_COND(avg_time != 0, avg_time, 1); service_tag_set_value_i64(service_info_ensure_tag(PSRV(p)->si->tags, "stat.total_reqpersec"), avg_counter / 4); service_tag_set_value_i64(service_info_ensure_tag(PSRV(p)->si->tags, "stat.total_avreqtime"), (avg_time)/(avg_counter)); /* send the registration now */ GError *err = register_namespace_service(PSRV(p)->si); if (err) { g_message("Service registration failed: (%d) %s", err->code, err->message); g_clear_error(&err); } }
static int _ds_feed(int fd, struct data_slab_s *ds) { while (ds->data.buffer.end < ds->data.buffer.alloc) { ssize_t r = read(fd, ds->data.buffer.buff + ds->data.buffer.end, ds->data.buffer.alloc - ds->data.buffer.end); if (r < 0) return MACRO_COND((errno==EAGAIN || errno==EWOULDBLOCK), RC_NOTREADY, RC_ERROR); if (r == 0) return RC_NODATA; ds->data.buffer.end += r; } return RC_PROCESSED; }
static guint _server_count_procs(void) { FILE *in; gchar line[512]; guint count = 0; in = fopen("/proc/cpuinfo", "r"); if (in) { while (fgets(line, sizeof(line), in)) { if (g_str_has_prefix(line, "processor")) count ++; } fclose(in); } return MACRO_COND(count < 2, 1, count); }
static struct meta1_service_url_s * __poll_services(struct meta1_backend_s *m1, guint replicas, struct compound_type_s *ct, guint seq, struct meta1_service_url_s **used, GError **err) { struct grid_lb_iterator_s *iter = NULL; struct service_info_s **siv = NULL; GRID_DEBUG("Polling %u [%s]", replicas, ct->fulltype); if (!(*err = _get_iterator(m1, ct, &iter))) { struct lb_next_opt_ext_s opt; memset(&opt, 0, sizeof(opt)); opt.req.distance = MACRO_COND(replicas>1,1,0); opt.req.max = replicas; opt.req.duplicates = FALSE; opt.req.stgclass = NULL; opt.req.strict_stgclass = TRUE; opt.srv_forbidden = __srvinfo_from_m1srvurl(m1->backend.lb, ct->baretype, used); opt.filter.hook = _filter_tag; opt.filter.data = ct; if (!grid_lb_iterator_next_set2(iter, &siv, &opt)) { EXTRA_ASSERT(siv == NULL); *err = NEWERROR(CODE_POLICY_NOT_SATISFIABLE, "No service available"); } grid_lb_iterator_clean(iter); iter = NULL; g_slist_free_full(opt.srv_forbidden, (GDestroyNotify)service_info_clean); } if(NULL != *err) return NULL; struct meta1_service_url_s *m1u = _siv_to_url (siv); service_info_cleanv(siv, FALSE); siv = NULL; g_strlcpy(m1u->srvtype, ct->type, sizeof(m1u->srvtype)); m1u->seq = seq; return m1u; }