char *handle_join(t_env *env, int cs, char *input) { t_channel *tmp; char *chan_name; char *ret; tmp = env->chans; if ((chan_name = get_chan_name(env, cs, input)) == NULL) return (NULL); while (tmp) { if (tmp->name && ft_strequ(tmp->name, chan_name)) { ret = join_msg(env, cs, tmp->id, chan_name); return (ret); } else if (tmp->next == NULL) { tmp->next = create_channel(tmp->id + 1, chan_name); return (join_msg(env, cs, tmp->id + 1, chan_name)); } tmp = tmp->next; } return (NULL); }
/************************************************************************** * WsCreateChannel [webservices.@] */ HRESULT WINAPI WsCreateChannel( WS_CHANNEL_TYPE type, WS_CHANNEL_BINDING binding, const WS_CHANNEL_PROPERTY *properties, ULONG count, const WS_SECURITY_DESCRIPTION *desc, WS_CHANNEL **handle, WS_ERROR *error ) { struct channel *channel; HRESULT hr; TRACE( "%u %u %p %u %p %p %p\n", type, binding, properties, count, desc, handle, error ); if (error) FIXME( "ignoring error parameter\n" ); if (desc) FIXME( "ignoring security description\n" ); if (!handle) return E_INVALIDARG; if (type != WS_CHANNEL_TYPE_REQUEST) { FIXME( "channel type %u not implemented\n", type ); return E_NOTIMPL; } if (binding != WS_HTTP_CHANNEL_BINDING) { FIXME( "channel binding %u not implemented\n", binding ); return E_NOTIMPL; } if ((hr = create_channel( type, binding, properties, count, &channel )) != S_OK) return hr; *handle = (WS_CHANNEL *)channel; return S_OK; }
static gboolean process_open_channel (CockpitRouter *self, const gchar *channel, JsonObject *options, GBytes *data, gpointer user_data) { GType (* type_function) (void) = user_data; GType channel_type = 0; const gchar *group; if (!cockpit_json_get_string (options, "group", "default", &group)) g_warning ("%s: caller specified invalid 'group' field in open message", channel); g_assert (type_function != NULL); channel_type = type_function (); if (g_str_equal (group, "fence")) g_hash_table_add (self->fences, g_strdup (channel)); g_hash_table_insert (self->groups, g_strdup (channel), g_strdup (group)); create_channel (self, channel, options, channel_type); return TRUE; }
PROCESS_THREAD(knot_controller_process, ev, data) { static struct etimer clean; PROCESS_BEGIN(); SENSORS_ACTIVATE(button_sensor); etimer_set(&clean,TIMER_INTERVAL); while (1){ PROCESS_WAIT_EVENT(); if (ev == tcpip_event && uip_newdata()) { network_handler(ev, data); } else if ((ev == PROCESS_EVENT_TIMER)){ if (data == &clean) { cleaner(); etimer_set(&clean,TIMER_INTERVAL); } } else if (ev == KNOT_EVENT_CONNECT){ create_channel((ServiceRecord *)data); } else if(ev == KNOT_EVENT_COMMAND){ send_actuator_command(*((int *)data)); } } PROCESS_END(); }
static void channel_np_connect_done(void * args) { ChannelConnectInfo * info = (ChannelConnectInfo *)((AsyncReqInfo *)args)->client_data; if (info->req.error) { if (info->req.error == EPERM) { info->req.error = set_fmt_errno(ERR_OTHER, "Failed to handshake the connection h:%s p:%s", info->host, info->port); } else if (info->req.error == ECONNREFUSED) { info->req.error = set_fmt_errno(ERR_OTHER, "Failed to establish connection h:%s p:%s", info->host, info->port); } if (info->np_sock) nopoll_conn_close(info->np_sock); info->callback(info->callback_args, info->req.error, NULL); } else { ChannelNP * c = create_channel(info->np_sock, info->is_ssl, 0); if (c == NULL) { if (info->np_sock) nopoll_conn_close(info->np_sock); info->callback(info->callback_args, errno, NULL); } else { set_peer_addr(c, info->addr_buf, info->addr_len); info->callback(info->callback_args, 0, &c->chan); } } nopoll_ctx_unref(info->np_ctx); loc_free(info->host); loc_free(info->port); loc_free(info->addr_buf); loc_free(info); }
/************************************************************************** * WsCreateServiceProxy [webservices.@] */ HRESULT WINAPI WsCreateServiceProxy( const WS_CHANNEL_TYPE type, const WS_CHANNEL_BINDING binding, const WS_SECURITY_DESCRIPTION *desc, const WS_PROXY_PROPERTY *proxy_props, ULONG proxy_props_count, const WS_CHANNEL_PROPERTY *channel_props, const ULONG channel_props_count, WS_SERVICE_PROXY **handle, WS_ERROR *error ) { struct channel *channel; HRESULT hr; TRACE( "%u %u %p %p %u %p %u %p %p\n", type, binding, desc, proxy_props, proxy_props_count, channel_props, channel_props_count, handle, error ); if (error) FIXME( "ignoring error parameter\n" ); if (desc) FIXME( "ignoring security description\n" ); if (!handle) return E_INVALIDARG; if ((hr = create_channel( type, binding, channel_props, channel_props_count, &channel )) != S_OK) return hr; if ((hr = create_proxy( channel, proxy_props, proxy_props_count, handle )) != S_OK) free_channel( channel ); return hr; }
void RedClient::handle_channels(RedPeer::InMessage* message) { SpiceMsgChannels *init = (SpiceMsgChannels *)message->data(); SpiceChannelId* channels = init->channels; for (unsigned int i = 0; i < init->num_of_channels; i++) { create_channel(channels[i].type, channels[i].id); } }
static void test_WsReceiveMessage( int port ) { WS_XML_STRING req = {9, (BYTE *)"req_test1"}, resp = {10, (BYTE *)"resp_test1"}, ns = {2, (BYTE *)"ns"}; WS_CHANNEL *channel; WS_MESSAGE *msg; WS_ELEMENT_DESCRIPTION body; WS_MESSAGE_DESCRIPTION desc_req, desc_resp; const WS_MESSAGE_DESCRIPTION *desc[1]; INT32 val = -1; HRESULT hr; hr = create_channel( port, &channel ); ok( hr == S_OK, "got %08x\n", hr ); hr = WsCreateMessageForChannel( channel, NULL, 0, &msg, NULL ); ok( hr == S_OK, "got %08x\n", hr ); body.elementLocalName = &req; body.elementNs = &ns; body.type = WS_INT32_TYPE; body.typeDescription = NULL; desc_req.action = &req; desc_req.bodyElementDescription = &body; hr = WsSendMessage( channel, msg, &desc_req, WS_WRITE_REQUIRED_VALUE, &val, sizeof(val), NULL, NULL ); ok( hr == S_OK, "got %08x\n", hr ); WsFreeMessage( msg ); hr = WsCreateMessageForChannel( channel, NULL, 0, &msg, NULL ); ok( hr == S_OK, "got %08x\n", hr ); body.elementLocalName = &resp; desc_resp.action = &resp; desc_resp.bodyElementDescription = &body; desc[0] = &desc_resp; hr = WsReceiveMessage( NULL, msg, desc, 1, WS_RECEIVE_REQUIRED_MESSAGE, WS_READ_REQUIRED_VALUE, NULL, &val, sizeof(val), NULL, NULL, NULL ); ok( hr == E_INVALIDARG, "got %08x\n", hr ); hr = WsReceiveMessage( channel, NULL, desc, 1, WS_RECEIVE_REQUIRED_MESSAGE, WS_READ_REQUIRED_VALUE, NULL, &val, sizeof(val), NULL, NULL, NULL ); ok( hr == E_INVALIDARG, "got %08x\n", hr ); hr = WsReceiveMessage( channel, msg, NULL, 1, WS_RECEIVE_REQUIRED_MESSAGE, WS_READ_REQUIRED_VALUE, NULL, &val, sizeof(val), NULL, NULL, NULL ); ok( hr == E_INVALIDARG, "got %08x\n", hr ); hr = WsReceiveMessage( channel, msg, desc, 1, WS_RECEIVE_REQUIRED_MESSAGE, WS_READ_REQUIRED_VALUE, NULL, &val, sizeof(val), NULL, NULL, NULL ); ok( hr == S_OK, "got %08x\n", hr ); ok( val == -2, "got %d\n", val ); hr = WsCloseChannel( channel, NULL, NULL ); ok( hr == S_OK, "got %08x\n", hr ); WsFreeChannel( channel ); WsFreeMessage( msg ); }
/************************************************************************** * WsCreateServiceProxyFromTemplate [webservices.@] */ HRESULT WINAPI WsCreateServiceProxyFromTemplate( WS_CHANNEL_TYPE channel_type, const WS_PROXY_PROPERTY *properties, const ULONG count, WS_BINDING_TEMPLATE_TYPE type, void *value, ULONG size, const void *desc, ULONG desc_size, WS_SERVICE_PROXY **handle, WS_ERROR *error ) { const WS_CHANNEL_PROPERTY *channel_props = NULL; ULONG channel_props_count = 0; WS_CHANNEL_BINDING binding; struct channel *channel; HRESULT hr; TRACE( "%u %p %u %u %p %u %p %u %p %p\n", channel_type, properties, count, type, value, size, desc, desc_size, handle, error ); if (error) FIXME( "ignoring error parameter\n" ); if (!desc || !handle) return E_INVALIDARG; FIXME( "ignoring description\n" ); switch (type) { case WS_HTTP_BINDING_TEMPLATE_TYPE: { WS_HTTP_BINDING_TEMPLATE *http = value; if (http) { channel_props = http->channelProperties.properties; channel_props_count = http->channelProperties.propertyCount; } binding = WS_HTTP_CHANNEL_BINDING; break; } case WS_HTTP_SSL_BINDING_TEMPLATE_TYPE: { WS_HTTP_SSL_BINDING_TEMPLATE *https = value; if (https) { channel_props = https->channelProperties.properties; channel_props_count = https->channelProperties.propertyCount; } binding = WS_HTTP_CHANNEL_BINDING; break; } default: FIXME( "template type %u not implemented\n", type ); return E_NOTIMPL; } if ((hr = create_channel( channel_type, binding, channel_props, channel_props_count, &channel )) != S_OK) return hr; if ((hr = create_proxy( channel, properties, count, handle )) != S_OK) free_channel( channel ); return hr; }
int add_in_channel(char *name, int fd, t_channel **root) { t_channel *tmp; tmp = (*root)->next; while (tmp != (*root)) { if (strcmp(tmp->channel_name, name) == 0) return (add_in_channel_aux(tmp, fd)); tmp = tmp->next; } return (create_channel(root, name, fd)); }
int main() { int i; for (i=0; i<10000; ++i) { if (i % 1000 == 0) printf("Connections: %d\n", i); create_channel(&channel, &client, NULL); create_dangling_policy_request(); destroy_channel(channel, client); } return 0; }
void join_command(int connfd,char* channel_name){ int length = 0; char back[MAX_MSG_LEN]; if(channel_valid(channel_name)){ /* if located channel exisits, part command is needed first */ user *u = user_table[connfd]; if(u->located_channel){ /* JOIN the same channel twice should be ignore */ if(!strcasecmp(u->located_channel->name,channel_name)) return; /* otherwise should PART the orignal channel first */ part_command(connfd,u->located_channel->name,1); } /* try to find a channel with the name of 'channel_name' */ channel* c; if(!(c = find_channel(channel_name))){ /* if no such channel, create a new one */ c = create_channel(channel_name); send_command_to_daemon("ADDCHAN",c->name); } u->located_channel = c; /* echo to all member */ length += snprintf(back + length, MAX_MSG_LEN - length, ":%s JOIN %s\n",u->nick_name,u->located_channel->name); invoke_channel(connfd,back,u->located_channel); /* add connfd into the channel list */ add_int_list(u->located_channel->member,connfd); /* write the list in the channel back back */ int_list* ufd; user* channelu; for(ufd = u->located_channel->member->next;ufd;ufd = ufd->next){ channelu = user_table[ufd->element]; length += snprintf(back + length, MAX_MSG_LEN - length, ":IRC_SERVER 353 %s = %s:%s\n", u->nick_name,channelu->located_channel->name,channelu->nick_name); } length += snprintf(back + length, MAX_MSG_LEN - length, ":IRC_SERVER 366 %s %s :End of /NAMES list\n",u->nick_name,u->located_channel->name); }else snprintf(back, MAX_MSG_LEN, "%s:No such channel\n",channel_name); send_msg_back(connfd,back); }
void handle_send_abort(char *cmd, t_server *server) { char *peer; t_channel *chan; peer = strtok(cmd, ":"); cmd = strtok(NULL, ""); if (!send_file || strcmp(send_file->peer, peer) != 0) return ; if ((chan = find_channel_by_name(server, peer)) == NULL) if ((chan = create_channel(peer, 0, server)) == NULL) return ; push_msg_to_channel(chan, "@client", cmd); close(send_file->fd); free(send_file); send_file = NULL; }
void handle_send_file(char *cmd, t_server *server) { char *from; t_channel *chan; char buff[512]; from = strtok(cmd, ":"); cmd = strtok(NULL, ""); if (!from || !cmd) return ; if ((chan = find_channel_by_name(server, from)) == NULL) if ((chan = create_channel(from, 0, server)) == NULL) return ; sprintf(buff, "New file (%s) from %s, to accept enter : /accept_file %s", cmd, from, from); push_msg_to_channel(chan, "@client", buff); }
void handle_send_end(char *cmd, t_server *server) { char *peer; t_channel *chan; peer = strtok(cmd, ":"); if (!send_file || strcmp(send_file->peer, peer) != 0 || send_file->status != 1) return ; close(send_file->fd); free(send_file); send_file = NULL; if ((chan = find_channel_by_name(server, peer)) == NULL) if ((chan = create_channel(peer, 0, server)) == NULL) return ; push_msg_to_channel(chan, "@client", "File finished"); }
int run() { fd_set fds; int max_fd; create_interface(&interface); running = true; accueil = NULL; accueil = create_channel("Accueil", 1, NULL); set_current_channel(accueil); while (running) { max_fd = init_fd(&fds); if (select(max_fd + 1, &fds, NULL, NULL, NULL) > 0) process_fd(&fds); } destroy_interface(&interface); return (0); }
static gboolean process_open_not_supported (CockpitRouter *self, const gchar *channel, JsonObject *options, GBytes *data, gpointer user_data) { const gchar *payload; if (!cockpit_json_get_string (options, "payload", NULL, &payload)) g_warning ("%s: caller specified invalid 'payload' field in open message", channel); else if (payload == NULL) g_warning ("%s: caller didn't provide a 'payload' field in open message", channel); else g_debug ("%s: bridge doesn't support channel: %s", channel, payload); /* This creates a temporary channel that closes with not-supported */ create_channel (self, channel, options, COCKPIT_TYPE_CHANNEL); return TRUE; }
static int netlink_init(void) { info("Starting experimental netlink support"); handle = nl_handle_alloc(); if (!handle) { error("Failed to allocate netlink handle"); return -ENOMEM; } if (genl_connect(handle) < 0) { error("Failed to connect to generic netlink"); nl_handle_destroy(handle); return -ENOLINK; } cache = genl_ctrl_alloc_cache(handle); if (!cache) { error("Failed to allocate generic netlink cache"); return -ENOMEM; nl_handle_destroy(handle); } family = genl_ctrl_search_by_name(cache, "bluetooth"); if (!family) { error("Failed to find Bluetooth netlink family"); nl_cache_free(cache); nl_handle_destroy(handle); return -ENOENT; } if (create_channel(nl_socket_get_fd(handle)) < 0) { error("Failed to create netlink IO channel"); genl_family_put(family); nl_cache_free(cache); nl_handle_destroy(handle); return -ENOMEM; } return 0; }
static void test_WsSendMessage( int port, WS_XML_STRING *action ) { WS_XML_STRING req = {9, (BYTE *)"req_test1"}, ns = {2, (BYTE *)"ns"}; WS_CHANNEL *channel; WS_MESSAGE *msg; WS_ELEMENT_DESCRIPTION body; WS_MESSAGE_DESCRIPTION desc; INT32 val = -1; HRESULT hr; hr = create_channel( port, &channel ); ok( hr == S_OK, "got %08x\n", hr ); hr = WsCreateMessageForChannel( channel, NULL, 0, &msg, NULL ); ok( hr == S_OK, "got %08x\n", hr ); body.elementLocalName = &req; body.elementNs = &ns; body.type = WS_INT32_TYPE; body.typeDescription = NULL; desc.action = action; desc.bodyElementDescription = &body; hr = WsSendMessage( NULL, msg, &desc, WS_WRITE_REQUIRED_VALUE, &val, sizeof(val), NULL, NULL ); ok( hr == E_INVALIDARG, "got %08x\n", hr ); hr = WsSendMessage( channel, NULL, &desc, WS_WRITE_REQUIRED_VALUE, &val, sizeof(val), NULL, NULL ); ok( hr == E_INVALIDARG, "got %08x\n", hr ); hr = WsSendMessage( channel, msg, NULL, WS_WRITE_REQUIRED_VALUE, &val, sizeof(val), NULL, NULL ); ok( hr == E_INVALIDARG, "got %08x\n", hr ); hr = WsSendMessage( channel, msg, &desc, WS_WRITE_REQUIRED_VALUE, &val, sizeof(val), NULL, NULL ); ok( hr == S_OK, "got %08x\n", hr ); hr = WsCloseChannel( channel, NULL, NULL ); ok( hr == S_OK, "got %08x\n", hr ); WsFreeChannel( channel ); WsFreeMessage( msg ); }
static void np_server_accept_done(void * x) { AsyncReqInfo * req = (AsyncReqInfo *)x; ServerNP * si = (ServerNP *)req->client_data; if (si->sock < 0) { /* Server closed. */ loc_free(si); return; } if (req->error) { trace(LOG_ALWAYS, "Socket accept failed: %s", errno_to_str(req->error)); } else { ChannelNP * c = create_channel(si->np_sock, si->is_ssl, 1); if (c == NULL) { trace(LOG_ALWAYS, "Cannot create channel for accepted connection: %s", errno_to_str(errno)); closesocket(req->u.acc.rval); } else { struct sockaddr * addr_buf; /* Socket remote address */ socklen_t addr_len; #if defined(SOCK_MAXADDRLEN) addr_len = SOCK_MAXADDRLEN; #else addr_len = 0x1000; #endif addr_buf = (struct sockaddr *)loc_alloc(addr_len); if (getpeername(nopoll_conn_socket (si->np_sock), addr_buf, &addr_len) < 0) { trace(LOG_ALWAYS, "Unable to get peer remote name: %s", errno_to_str(errno)); closesocket(req->u.acc.rval); } else { set_peer_addr(c, addr_buf, addr_len); si->serv.new_conn(&si->serv, &c->chan); } loc_free(addr_buf); } } async_req_post(req); }
int aout_sles_open(rh_aout_itf self, unsigned int channels, unsigned int rate, unsigned int samplesize, unsigned int bigendian) { struct aout_instance * instance = (struct aout_instance *)self; if( instance != NULL ) { if(instance->channels == channels && instance->samplerate == rate && instance->samplesize == samplesize && instance->bigendian == bigendian) { return 0; // channel is already open, and the correct format. } // channel is open, but the wrong format, close it. destroy_channel(self); } // open new channel. { if( instance ) { instance->channels = channels; instance->samplerate = rate; instance->samplesize = samplesize; instance->bigendian = bigendian; buffer_queue_alloc( &instance->bq, 3, 32 * 1024 ); // 3 32k periods. buffer_queue_alloc_buffers(&instance->bq); create_channel(self); return 0; } return -1; } }
static struct iio_device * create_device(struct iio_context *ctx, xmlNode *n) { xmlAttr *attr; struct iio_device *dev = calloc(1, sizeof(*dev)); if (!dev) return NULL; dev->ctx = ctx; for (attr = n->properties; attr; attr = attr->next) { if (!strcmp((char *) attr->name, "name")) { dev->name = _strdup((char *) attr->children->content); } else if (!strcmp((char *) attr->name, "id")) { dev->id = _strdup((char *) attr->children->content); } else { WARNING("Unknown attribute \'%s\' in <device>\n", attr->name); } } if (!dev->id) { ERROR("Unable to read device ID\n"); goto err_free_device; } for (n = n->children; n; n = n->next) { if (!strcmp((char *) n->name, "channel")) { struct iio_channel **chns, *chn = create_channel(dev, n); if (!chn) { ERROR("Unable to create channel\n"); goto err_free_device; } chns = realloc(dev->channels, (1 + dev->nb_channels) * sizeof(struct iio_channel *)); if (!chns) { ERROR("Unable to allocate memory\n"); free(chn); goto err_free_device; } chns[dev->nb_channels++] = chn; dev->channels = chns; } else if (!strcmp((char *) n->name, "attribute")) { if (add_attr_to_device(dev, n, false) < 0) goto err_free_device; } else if (!strcmp((char *) n->name, "debug-attribute")) { if (add_attr_to_device(dev, n, true) < 0) goto err_free_device; } else if (strcmp((char *) n->name, "text")) { WARNING("Unknown children \'%s\' in <device>\n", n->name); continue; } } dev->words = (dev->nb_channels + 31) / 32; if (dev->words) { dev->mask = calloc(dev->words, sizeof(*dev->mask)); if (!dev->mask) { errno = ENOMEM; goto err_free_device; } } return dev; err_free_device: free_device(dev); return NULL; }
/* ** cmd_channel() ** ** Standard channel processing command for player input. Most channel- ** oriented systems will use this to get standardized channel manipulation. ** ** channel_type is: ** 0 normal ** 1 intermud */ varargs nomask void cmd_channel(string channel_name, string arg, int channel_type) { class channel_info ci = query_channel_info(channel_name); object tb; int listening; string user_channel_name; string sender_name; tb = this_body(); listening = member_array(channel_name, tb->query_channel_list()) != -1; user_channel_name = user_channel_name(channel_name); if ( !arg || arg == "" ) { if ( listening ) { printf("You are presently listening to '%s'.\n", user_channel_name); print_mod_info(channel_name); } else { printf("You are not listening to '%s'.\n", user_channel_name); } return; } if ( arg[0..3] == "/new" ) { string * options = explode(arg[4..], " "); if ( ci ) { if ( sizeof(options) ) printf("'%s' already exists; modifying options...\n", user_channel_name); else printf("'%s' already exists.\n", user_channel_name); } else { create_channel(channel_name); printf("'%s' has been created.\n", user_channel_name); } ci = query_channel_info(channel_name); foreach ( string option in options ) { switch ( option ) { case "admin": if ( !adminp(this_user()) ) { printf("Only admins can create admin channels.\n"); return; } set_flags(channel_name, CHANNEL_ADMIN_ONLY); printf(" --> only admins may tune in\n"); break; case "wiz": case "wizard": /* ### need better security? */ if ( (ci->flags & CHANNEL_ADMIN_ONLY) && !adminp(this_user()) ) { printf("Only admins can turn off admin-only.\n"); return; } else if ( !wizardp(this_user()) ) { printf("Only wizards can create wizard channels.\n"); return; } set_flags(channel_name, CHANNEL_WIZ_ONLY); printf(" --> only wizards may tune in\n"); break; case "permanent": /* ### need better security? */ if ( !adminp(this_user()) ) { printf("Only admins can tweak permanent channels.\n"); return; } set_permanent(channel_name, 1); printf(" --> the channel is permanent\n"); break; case "nopermanent": case "goaway": /* ### need better security? */ if ( !adminp(this_user()) ) { printf("Only admins can tweak permanent channels.\n"); return; } set_permanent(channel_name, 0); printf(" --> the channel may now go away\n"); test_for_purge(channel_name); break; } } /* tune the channel in now */ arg = "/on"; }
void main_term_scope(void *data) //@ requires term_perm(?termScope, false); //@ ensures term_perm(termScope, false); //@ terminates; { //@ int space = create_obligation_space(); //@ level level = create_level(nil, nil); //@ int creditObject = create_obspace_credit_object(space, level); //@ obspace_credit_object_get_info(); info info = malloc(sizeof(struct info)); if (info == 0) abort(); //@ info->nextToSend = 0; //@ info->nextToReceive = 0; //@ info->space = space; //@ info->termScope = termScope; //@ info->level = level; //@ info->creditObject = creditObject; //@ close channel_inv(info)(nil); //@ close exists(channel_inv(info)); //@ close exists<real>(1/3); channel channel = create_channel(); info->channel = channel; //@ close debits(0, creditObject); //@ close credits(0, creditObject); /*@ for (int i = 0; i < 10; i++) invariant 0 <= i &*& i <= 10 &*& [_]obspace_credit_object_info(creditObject, space, level) &*& [2/3]obligation_space(space, termScope) &*& obspace_obligation_set(space, n_times(nat_of_int(i), level)) &*& debits(i, creditObject) &*& credits(i, creditObject); decreases 10 - i; { create_obspace_debit(); close debits(i + 1, creditObject); close credits(i + 1, creditObject); succ_int(i); } @*/ //@ close channel_send_tokens(0, channel, space, termScope, level, creditObject, channel_inv(info)); /*@ for (int i = 0; i < 10; i++) invariant 0 <= i &*& i <= 10 &*& [2/3]obligation_space(space, termScope) &*& channel_handle(channel, 1, space, termScope, 1/3, level, creditObject, channel_inv(info), i) &*& channel_send_tokens(i, channel, space, termScope, level, creditObject, channel_inv(info)); decreases 10 - i; { channel_create_send_token(channel); close channel_send_tokens(i + 1, channel, space, termScope, level, creditObject, channel_inv(info)); } @*/ /*@ produce_function_pointer_chunk thread_run_with_obligations(producer)(termScope, space, n_times(nat_of_int(10), level), producer_pre(space, termScope, level))(data_) { open producer_pre(space, termScope, level)(data_); call(); } @*/ //@ remove_all_append(n_times(nat_of_int(10), level), nil); //@ assert remove_all(n_times(nat_of_int(10), level), n_times(nat_of_int(10), level)) == nil; //@ close [1/2]info(info, channel, space, termScope, level, creditObject); //@ close producer_pre(space, termScope, level)(info); //@ produce_call_below_perm_(); //@ call_below_perm__elim(main_term_scope); //@ consume_call_perm_for(producer); thread_start_with_obligations(producer, info); for (unsigned int i = 0; i < 10; i = i + 1) /*@ invariant channel_handle(channel, 1, space, termScope, 1/3, level, creditObject, channel_inv(info), 10 - i) &*& [1/3]obligation_space(space, termScope) &*& obspace_obligation_set(space, nil) &*& credits(10 - i, creditObject) &*& [1/2]info->nextToReceive |-> i &*& 0 <= i &*& i <= 10; @*/ //@ decreases 10 - (int)i; { { /*@ predicate P() = [1/2]info->nextToReceive |-> i; predicate Q(void *result) = [1/2]info->nextToReceive |-> i + 1 &*& result == (void *)i; lemma void op() requires channel_inv(info)(cons(?elem, ?elems)) &*& P(); ensures channel_inv(info)(elems) &*& Q(elem); { open channel_inv(info)(_); open P(); is_range_length(info->nextToReceive, cons(elem, elems), info->nextToSend); info->nextToReceive++; close channel_inv(info)(elems); close Q(elem); } @*/ //@ produce_lemma_function_pointer_chunk(op) : channel_receive_ghost_op(channel_inv(info), P, Q)() { call(); }; //@ close P(); //@ open credits(_, _); void *x = channel_receive(channel); //@ open Q(x); assert(x == (void *)i); } } channel_dispose(channel); //@ close [1/2]info(info, _, _, _, _, _); //@ open channel_inv(info)(nil); free(info); //@ open credits(0, creditObject); //@ leak obspace_credit_object(creditObject, space, level, 0, 0); //@ leak obspace_obligation_set(space, nil); //@ open obligation_space(space, termScope); //@ assert [_]ghost_cell<pair<int, real> >(space, pair(?scope, ?olevel)); //@ leak atomic_space(olevel, obligation_space_inv(scope, termScope)); }
/** * Builds the Chariot test. * * @param i_testHandle Test object to be configured. */ static void build_test( CHR_TEST_HANDLE i_testHandle) { CHR_CHANNEL_HANDLE channel1; CHR_CHANNEL_HANDLE channel2; CHR_CHANNEL_HANDLE channel3; CHR_RECEIVER_HANDLE receiver1; CHR_RUNOPTS_HANDLE runOptionsHandle; CHR_API_RC rc; rc = CHR_test_set_filename( i_testHandle, lc_testFile, strlen(lc_testFile)); if (rc != CHR_OK) show_error(i_testHandle, rc, "test_set_filename"); /* * Create channel objects. */ channel1 = create_channel(&lc_channelSpec1); channel2 = create_channel(&lc_channelSpec2); channel3 = create_channel(&lc_channelSpec3); /* * Add channels to test. */ rc = CHR_test_add_channel(i_testHandle, channel1); if (rc != CHR_OK) show_error(i_testHandle, rc, "test_add_channel"); rc = CHR_test_add_channel(i_testHandle, channel2); if (rc != CHR_OK) show_error(i_testHandle, rc, "test_add_channel"); rc = CHR_test_add_channel(i_testHandle, channel3); if (rc != CHR_OK) show_error(i_testHandle, rc, "test_add_channel"); /* * Create receiver objects. */ receiver1 = create_receiver(&lc_receiverSpec1); /* * Create IPTV pairs. */ create_pair(receiver1, channel1); create_pair(receiver1, channel2); create_pair(receiver1, channel3); /* * Add receivers to test. */ rc = CHR_test_add_receiver(i_testHandle, receiver1); if (rc != CHR_OK) show_error(i_testHandle, rc, "test_add_receiver"); /* * Set a time limit on the test. */ rc = CHR_test_get_runopts(i_testHandle, &runOptionsHandle); if (rc != CHR_OK) show_error(i_testHandle, rc, "test_get_runopts"); rc = CHR_runopts_set_test_duration( runOptionsHandle, TEST_DURATION); if (rc != CHR_OK) show_error(i_testHandle, rc, "runopts_set_test_duration"); rc = CHR_runopts_set_test_end( runOptionsHandle, CHR_TEST_END_AFTER_FIXED_DURATION); if (rc != CHR_OK) show_error(i_testHandle, rc, "runopts_set_test_end"); } /* build_test */
static int server( int argc, char *argv[] ) { /*--- Connect to one messip server ---*/ display( "Start process\n" ); messip_init( ); messip_cnx_t *cnx = messip_connect( NULL, "ex8/p1", MESSIP_NOTIMEOUT ); if ( !cnx ) cancel( "Unable to find messip server\n" ); /*--- Create 5 channels ---*/ messip_channel_t *ch1 = create_channel( cnx, "one" ); messip_channel_t *ch2 = create_channel( cnx, "two" ); messip_channel_t *ch3 = create_channel( cnx, "three" ); messip_channel_t *ch4 = create_channel( cnx, "four" ); messip_channel_t *ch5 = create_channel( cnx, "five" ); /*--- Now delete the 3rd channel ---*/ display( "Channels have been created. Waiting 15 seconds...\n" ); delay( 15000 ); int status = messip_channel_delete( ch3, MESSIP_NOTIMEOUT ); display( "messip_channel_delete #3: status=%d\n", status ); assert(status == 0); delay( 15000 ); /*--- Attach to channel four ---*/ messip_channel_t *xch4 = messip_channel_connect( cnx, "four", MESSIP_NOTIMEOUT ); assert(xch4 != NULL); status = messip_channel_delete( ch4, MESSIP_NOTIMEOUT ); display( "messip_channel_delete #4: status=%d\n", status ); assert(status == 1); /*--- Now delete the 4th channel ---*/ status = messip_channel_disconnect( xch4, MESSIP_NOTIMEOUT ); display( "messip_channel_disconnect #4: status=%d\n", status ); status = messip_channel_delete( ch4, MESSIP_NOTIMEOUT ); display( "messip_channel_delete #4: status=%d\n", status ); assert(status == 0); /*--- Now wait for one message on this on channel ---*/ display( "Wait now 10 seconds...\n" ); delay( 10000 ); char rec_buff[ 80 ]; memset( rec_buff, 0, sizeof(rec_buff) ); int32_t type; int index = messip_receive( ch1, &type, rec_buff, sizeof(rec_buff), MESSIP_NOTIMEOUT ); if ( index == -1 ) { fprintf( stderr, "Error on receive message on channel '%s'\n", "one" ); return -1; } display( "received %d-%d:'%s' type=%d from id=%s index=%d\n", ch1->datalen, ch1->datalenr, rec_buff, type, ch1->remote_id, index ); assert( !strcmp( rec_buff, "Hello" ) ); assert( type == 1961 ); display( "...waiting 10 seconds before replying to the client...\n" ); delay( 10000 ); messip_reply( ch1, index, 3005, "Bonjour", 8, MESSIP_NOTIMEOUT ); /*--- Wait now channel-deconnexion message ---*/ memset( rec_buff, 0, sizeof(rec_buff) ); index = messip_receive( ch1, &type, rec_buff, sizeof(rec_buff), MESSIP_NOTIMEOUT ); if ( index == -1 ) { fprintf( stderr, "Error on receive message on channel '%s'\n", "one" ); return -1; } display( "received %d-%d:'%s' type=%d from %s index=%d\n", ch1->datalen, ch1->datalenr, rec_buff, type, ch1->remote_id, index ); assert(index==MESSIP_MSG_DISCONNECT || index==MESSIP_MSG_DISMISSED); display( "End process\n" ); return 0; } // server
SharedDictionary Router::handle_command(SharedClient client, SharedDictionary command) { if (!command->contains("key")) { DEBUGMSG("Received illegal command message\n"); return SharedDictionary(); } long key = command->get<int>("key", -1); switch (command->get<int>("code", -1)) { case ECHO_COMMAND_LOOKUP: { string channel_alias = command->get<string>("alias", ""); string channel_type = command->get<string>("type", ""); bool create = command->get<bool>("create", true); if (channel_alias.size() == 0) { return generate_error_command(key, "Channel argument not provided or illegal"); } bool found = aliases.find(channel_alias) != aliases.end(); if (!found && !create) return generate_error_command(key, "Channel does not exist"); if(create) { if(!found) { SharedChannel channel = create_channel(channel_alias, client, channel_type); } } int id = aliases[channel_alias]; if (channel_type.empty() || channels[id]->get_type().empty() || channels[id]->get_type() == channel_type) { channels[id]->set_type(channel_type); SharedDictionary command = generate_command(ECHO_COMMAND_RESULT); command->set<string>("alias", channel_alias); command->set<string>("type", channels[id]->get_type()); command->set<int>("channel", id); command->set<int>("key", key); return command; } else { return generate_error_command(key, "Channel type does not match"); } } case ECHO_COMMAND_SUBSCRIBE: { int channel_id = command->get<int>("channel", ECHO_COMMAND_UNKNOWN); if (channels.find(channel_id) == channels.end()) { return generate_error_command(key, "Channel does not exist"); } if (!channels[channel_id]->subscribe(client)) { return generate_error_command(key, "Already subscribed"); } return generate_confirm_command(key); } case ECHO_COMMAND_SUBSCRIBE_ALIAS: { string channel_alias = command->get<string>("channel", ""); auto channel_id = aliases[channel_alias]; if (channels.find(channel_id) == channels.end()) { return generate_error_command(key, "Channel does not exist"); } if (!channels[channel_id]->subscribe(client)) { return generate_error_command(key, "Already subscribed"); } auto ret = generate_confirm_command(key); ret->set<string>("alias", channel_alias); ret->set<int>("channel_id",channel_id); return ret; } case ECHO_COMMAND_CREATE_CHANNEL_WITH_ALIAS: { string channel_alias = command->get<string>("channel", ""); string channel_type = command->get<string>("type", ""); create_channel(channel_alias, client, channel_type); return generate_confirm_command(key); } case ECHO_COMMAND_UNSUBSCRIBE: { int channel_id = command->get<int>("channel", -1); if (channels.find(channel_id) == channels.end()) { return generate_error_command(key, "Channel does not exist"); } if (!channels[channel_id]->unsubscribe(client)) { return generate_error_command(key, "Not subscribed"); } return generate_confirm_command(key); } case ECHO_COMMAND_WATCH: { int channel_id = command->get<int>("channel", -1); if (channels.find(channel_id) == channels.end()) { return generate_error_command(key, "Channel does not exist"); } if (!channels[channel_id]->watch(client)) { return generate_error_command(key, "Already watching"); } return generate_confirm_command(key); } case ECHO_COMMAND_UNWATCH: { int channel_id = command->get<int>("channel", -1); if (channels.find(channel_id) == channels.end()) { return generate_error_command(key, "Channel does not exist"); } if (!channels[channel_id]->unwatch(client)) { return generate_error_command(key, "Not watching"); } return generate_confirm_command(key); } } return generate_error_command(key,"Message unhandled"); }
//,b8 ,2a ,00 ,00 ,00 ,c3 int main() { u64 magic_number; octen_message message; program_channel = create_channel(program_channel_name, 0x4000, 0x4000, 30000); if(!read_channel(program_channel, &magic_number, sizeof(u64))) error("Client disconnected!\n"); if(magic_number != 0x3e3e6b6f3c3c2000) error("Program didn't give the magic number!\n"); if(!write_channel(program_channel, &magic_number, sizeof(u64))) error("Client disconnected!\n"); compile_buffer = allocate(0, 0x1000, PAGE_RWX); void *program_function; message = create_message(0x1000, CMD_ALOC); if(!write_channel(program_channel, &message, sizeof(octen_message))) error("Client disconnected!\n"); if(!read_channel(program_channel, &program_function, sizeof(void*))) error("Client disconnected!\n"); while(true) { char input_buffer[256]; printf("* "); #ifdef OS_WINDOWS fflush(stdin); #else __fpurge(stdin); #endif scanf("%255[^\n]", input_buffer); if(strcmp("quit", input_buffer)==0) break; if(strcmp("call", input_buffer)==0 && program_function) { message = create_message(0, CMD_CALL); if(!write_channel(program_channel, &message, sizeof(octen_message))) error("Client disconnected!\n"); if(!write_channel(program_channel, &program_function, sizeof(void*))) error("Client disconnected!\n"); u64 result; if(!read_channel(program_channel, &result, sizeof(u64))) error("Client disconnected!\n"); printf("%u\n", (u32)result); continue; } eval_string(input_buffer, compile_buffer); message = create_message(0x1000, CMD_SET_EXEC); if(!write_channel(program_channel, &message, sizeof(octen_message))) error("Client disconnected!\n"); if(!write_channel(program_channel, &program_function, sizeof(void*))) error("Client disconnected!\n"); if(!write_channel(program_channel, compile_buffer, 0x1000)) error("Client disconnected!\n"); if(!read_channel(program_channel, &message, sizeof(octen_message))) error("Client disconnected!\n"); } disconnect_channel(program_channel); return 0; }