Example #1
0
static void init_server(rwmsg_perf_task_t *t) {
  rw_status_t rs = RW_STATUS_FAILURE;
  UNUSED(rs);

  printf("Task %d server, path '%s' starting...\n", t->num, t->path);

  t->m = calloc(t->cfg.size, 1);

  t->sc = rwmsg_srvchan_create(t->ep);
  assert(t->sc);

  t->sig = rwmsg_signature_create(t->ep, RWMSG_PAYFMT_RAW, 1, RWMSG_PRIORITY_DEFAULT);
  assert(t->sig);

  rwmsg_closure_t cb;
  cb.request = server_method_1;
  cb.ud = t;
  t->meth = rwmsg_method_create(t->ep, t->path, t->sig, &cb);
  assert(t->meth);

  rs = rwmsg_srvchan_add_method(t->sc, t->meth);

  rs = rwmsg_srvchan_bind_rwsched_queue(t->sc, t->rws_q);
  assert(rs == RW_STATUS_SUCCESS);
}
rw_status_t
rwlogd_create_server_endpoint(rwlogd_instance_ptr_t instance)
{
  rw_status_t rwstatus;
  // Instantiate server interface
  char *my_path;

  int r = asprintf(&my_path, 
                   "/R/%s/%d",
                   RWLOGD_PROC,
                   instance->rwtasklet_info->identity.rwtasklet_instance_id);
  RW_ASSERT(r != -1);
  if ( r == -1) {
    return RW_STATUS_FAILURE;
  }


  RW_ASSERT(instance->rwtasklet_info->rwmsg_endpoint);
  if (!instance->rwtasklet_info->rwmsg_endpoint) {
    return RW_STATUS_FAILURE;
  }
  // Create a server channel that tasklet uses to recieve messages from clients
  instance->sc = rwmsg_srvchan_create(instance->rwtasklet_info->rwmsg_endpoint);
  RW_ASSERT(instance->sc);
  if (!instance->sc) {
    return RW_STATUS_FAILURE;
  }

  //Initialize the protobuf service
  RWLOGD__INITSERVER(&instance->rwlogd_srv, rwlogd_);
  // Bind a single service for tasklet namespace
  rwstatus = rwmsg_srvchan_add_service(instance->sc,
                                       my_path,
                                       (ProtobufCService *)&instance->rwlogd_srv,
                                       instance);
  RW_ASSERT(rwstatus == RW_STATUS_SUCCESS);
  if (rwstatus != RW_STATUS_SUCCESS) {
    return rwstatus;
  }

  RWLOGD_PEER_API__INITSERVER(&instance->rwlogd_peerapi_srv,rwlogd_);
  rwstatus = rwmsg_srvchan_add_service(instance->sc,
                                       my_path,
                                       (ProtobufCService *)&instance->rwlogd_peerapi_srv,
                                       instance);
  RW_ASSERT(rwstatus == RW_STATUS_SUCCESS);
  if (rwstatus != RW_STATUS_SUCCESS) {
    return rwstatus;
  }


  // Bind this srvchan to rwsched's taskletized cfrunloop
  // This will result in events executing in the cfrunloop context
  // rwsched_CFRunLoopRef runloop = rwsched_tasklet_CFRunLoopGetCurrent(tenv.rwsched);
  rwstatus = rwmsg_srvchan_bind_rwsched_cfrunloop(instance->sc,
                                                    instance->rwtasklet_info->rwsched_tasklet_info);
  RW_ASSERT(rwstatus == RW_STATUS_SUCCESS);
  if (rwstatus != RW_STATUS_SUCCESS) {
    return rwstatus;
  }

  free(my_path);
  return rwstatus;
}