本文整理汇总了C++中write_stringz函数的典型用法代码示例。如果您正苦于以下问题:C++ write_stringz函数的具体用法?C++ write_stringz怎么用?C++ write_stringz使用的例子?那么, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了write_stringz函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: command_get_context
static void command_get_context(char * token, Channel * c) {
int err = 0;
char id[256];
Context * ctx = NULL;
json_read_string(&c->inp, id, sizeof(id));
if (read_stream(&c->inp) != 0) exception(ERR_JSON_SYNTAX);
if (read_stream(&c->inp) != MARKER_EOM) exception(ERR_JSON_SYNTAX);
ctx = id2ctx(id);
if (ctx == NULL) err = ERR_INV_CONTEXT;
else if (ctx->exited) err = ERR_ALREADY_EXITED;
if (err) {
write_stringz(&c->out, "R");
write_stringz(&c->out, token);
write_errno(&c->out, err);
write_stringz(&c->out, "null");
write_stream(&c->out, MARKER_EOM);
}
else {
/* Need to stop everything to access context properties.
* In particular, proc FS access can fail when process is running.
*/
GetContextArgs * s = loc_alloc_zero(sizeof(GetContextArgs));
s->c = c;
stream_lock(c);
strcpy(s->token, token);
s->ctx = ctx;
context_lock(ctx);
id2pid(id, &s->parent);
post_safe_event(ctx->mem, event_get_context, s);
}
}
示例2: send_event_register_changed
void send_event_register_changed(const char * id) {
unsigned i;
Context * ctx = NULL;
int frame = STACK_NO_FRAME;
RegisterDefinition * def = NULL;
OutputStream * out = &broadcast_group->out;
id2register(id, &ctx, &frame, &def);
if (ctx == NULL) return;
for (i = 0; i < listener_cnt; i++) {
Listener * l = listeners + i;
if (l->func->register_changed == NULL) continue;
l->func->register_changed(ctx, frame, def, l->args);
}
if (frame >= 0 && frame == get_top_frame(ctx)) {
id = register2id(ctx, STACK_TOP_FRAME, def);
}
write_stringz(out, "E");
write_stringz(out, REGISTERS);
write_stringz(out, "registerChanged");
json_write_string(out, id);
write_stream(out, 0);
write_stream(out, MARKER_EOM);
}
示例3: event_get_context
static void event_get_context(void * arg) {
GetContextArgs * s = (GetContextArgs *)arg;
Channel * c = s->c;
Context * ctx = s->ctx;
if (!is_stream_closed(c)) {
int err = 0;
write_stringz(&c->out, "R");
write_stringz(&c->out, s->token);
if (ctx->exited) err = ERR_ALREADY_EXITED;
write_errno(&c->out, err);
if (err == 0) {
write_context(&c->out, ctx, s->parent != 0);
write_stream(&c->out, 0);
}
else {
write_stringz(&c->out, "null");
}
write_stream(&c->out, MARKER_EOM);
flush_stream(&c->out);
}
stream_unlock(c);
context_unlock(ctx);
loc_free(s);
}
示例4: command_get_context_cache_client
static void command_get_context_cache_client(void * x) {
GetContextArgs * args = (GetContextArgs *)x;
Channel * c = cache_channel();
Context * ctx = NULL;
int frame = STACK_NO_FRAME;
RegisterDefinition * reg_def = NULL;
Trap trap;
if (set_trap(&trap)) {
if (id2register(args->id, &ctx, &frame, ®_def) < 0) exception(errno);
clear_trap(&trap);
}
cache_exit();
write_stringz(&c->out, "R");
write_stringz(&c->out, args->token);
write_errno(&c->out, trap.error);
if (reg_def != NULL) {
write_context(&c->out, args->id, ctx, frame, reg_def);
}
else {
write_stringz(&c->out, "null");
}
write_stream(&c->out, MARKER_EOM);
}
示例5: command_write
static void command_write(char * token, Channel * c) {
char id[256];
long size;
int err = 0;
json_read_string(&c->inp, id, sizeof(id));
json_test_char(&c->inp, MARKER_EOA);
size = json_read_long(&c->inp);
json_test_char(&c->inp, MARKER_EOA);
if (virtual_stream_write(c, token, id, size, &c->inp) < 0) err = errno;
json_test_char(&c->inp, MARKER_EOA);
json_test_char(&c->inp, MARKER_EOM);
if (err != 0) {
/*
* Handle reply with an error. If none error was detected, the reply
* was sent back by virtual_stream_write() or delayed.
*/
write_stringz(&c->out, "R");
write_stringz(&c->out, token);
write_errno(&c->out, err);
write_stream(&c->out, MARKER_EOM);
}
}
示例6: virtual_stream_eos
int virtual_stream_eos(Channel * c, char * token, char * id) {
size_t done = 0;
WriteRequest * r = NULL;
int err = 0;
StreamClient * client = find_client(id, c);
if (client == NULL) err = errno;
if (!err && (client->stream->access & VS_ENABLE_REMOTE_WRITE) == 0) err = ERR_UNSUPPORTED;
if (!err && !list_is_empty(&client->write_requests)) r = (WriteRequest *)loc_alloc_zero(sizeof(WriteRequest));
if (!err && r == NULL && virtual_stream_add_data(client->stream, NULL, 0, &done, 1) < 0) err = errno;
if (r != NULL) {
list_init(&r->link_client);
r->client = client;
r->eos = 1;
strlcpy(r->token, token, sizeof(r->token));
list_add_last(&r->link_client, &client->write_requests);
}
else if (err == 0) {
write_stringz(&c->out, "R");
write_stringz(&c->out, token);
write_errno(&c->out, err);
write_stream(&c->out, MARKER_EOM);
}
if (err != 0) errno = err;
return err == 0 ? 0 : -1;
}
示例7: command_set_signal_mask
static void command_set_signal_mask(char * token, Channel * c) {
int err = 0;
char id[256];
pid_t pid;
Context * ctx = NULL;
int dont_stop;
int dont_pass;
json_read_string(&c->inp, id, sizeof(id));
if (read_stream(&c->inp) != 0) exception(ERR_JSON_SYNTAX);
dont_stop = json_read_long(&c->inp);
if (read_stream(&c->inp) != 0) exception(ERR_JSON_SYNTAX);
dont_pass = json_read_long(&c->inp);
if (read_stream(&c->inp) != 0) exception(ERR_JSON_SYNTAX);
if (read_stream(&c->inp) != MARKER_EOM) exception(ERR_JSON_SYNTAX);
pid = id2pid(id, NULL);
ctx = context_find_from_pid(pid);
if (ctx == NULL) {
err = ERR_INV_CONTEXT;
}
else {
ctx->sig_dont_stop = dont_stop;
ctx->sig_dont_pass = dont_pass;
}
write_stringz(&c->out, "R");
write_stringz(&c->out, token);
write_errno(&c->out, err);
write_stream(&c->out, MARKER_EOM);
}
示例8: command_signal
static void command_signal(char * token, Channel * c) {
int err = 0;
char id[256];
int signal = 0;
pid_t pid, parent;
json_read_string(&c->inp, id, sizeof(id));
if (read_stream(&c->inp) != 0) exception(ERR_JSON_SYNTAX);
signal = (int)json_read_long(&c->inp);
if (read_stream(&c->inp) != 0) exception(ERR_JSON_SYNTAX);
if (read_stream(&c->inp) != MARKER_EOM) exception(ERR_JSON_SYNTAX);
pid = id2pid(id, &parent);
write_stringz(&c->out, "R");
write_stringz(&c->out, token);
#if defined(WIN32)
err = ENOSYS;
#elif defined(_WRS_KERNEL)
if (kill(pid, signal) < 0) err = errno;
#elif defined(__APPLE__)
if (kill(pid, signal) < 0) err = errno;
#else
if (parent == 0) {
if (kill(pid, signal) < 0) err = errno;
}
else {
if (tkill(pid, signal) < 0) err = errno;
}
#endif
write_errno(&c->out, err);
write_stream(&c->out, MARKER_EOM);
}
示例9: command_terminate
static void command_terminate(char * token, Channel * c) {
int err = 0;
char id[256];
pid_t pid, parent;
json_read_string(&c->inp, id, sizeof(id));
if (read_stream(&c->inp) != 0) exception(ERR_JSON_SYNTAX);
if (read_stream(&c->inp) != MARKER_EOM) exception(ERR_JSON_SYNTAX);
pid = id2pid(id, &parent);
write_stringz(&c->out, "R");
write_stringz(&c->out, token);
if (parent != 0) {
err = ERR_INV_CONTEXT;
}
else {
#if defined(WIN32)
HANDLE h = OpenProcess(PROCESS_TERMINATE, FALSE, pid);
if (h == NULL) {
err = ERR_INV_CONTEXT;
}
else {
TerminateProcess(h, 1);
CloseHandle(h);
}
#else
if (kill(pid, SIGTERM) < 0) err = errno;
#endif
}
write_errno(&c->out, err);
write_stream(&c->out, MARKER_EOM);
}
示例10: command_get_state
static void command_get_state(char * token, Channel * c) {
char id[256];
Context * ctx;
int err = 0;
json_read_string(&c->inp, id, sizeof(id));
if (read_stream(&c->inp) != 0) exception(ERR_JSON_SYNTAX);
if (read_stream(&c->inp) != MARKER_EOM) exception(ERR_JSON_SYNTAX);
ctx = id2ctx(id);
write_stringz(&c->out, "R");
write_stringz(&c->out, token);
if (ctx == NULL) err = ERR_INV_CONTEXT;
else if (ctx->exited) err = ERR_ALREADY_EXITED;
write_errno(&c->out, err);
json_write_boolean(&c->out, ctx != NULL && ctx->intercepted);
write_stream(&c->out, 0);
if (err) {
write_stringz(&c->out, "0");
write_stringz(&c->out, "null");
write_stringz(&c->out, "null");
}
else {
write_context_state(&c->out, ctx);
}
write_stream(&c->out, MARKER_EOM);
}
示例11: command_unsubscribe
static void command_unsubscribe(char * token, Channel * c) {
char type[256];
int err = 0;
Subscription * s = NULL;
LINK * l;
json_read_string(&c->inp, type, sizeof(type));
if (read_stream(&c->inp) != 0) exception(ERR_JSON_SYNTAX);
if (read_stream(&c->inp) != MARKER_EOM) exception(ERR_JSON_SYNTAX);
for (l = subscriptions.next; l != &subscriptions;) {
Subscription * h = all2subscription(l);
l = l->next;
if (h->channel == c && strcmp(type, h->type) == 0) {
s = h;
break;
}
}
if (s == NULL) err = ERR_INV_CONTEXT;
if (err == 0) delete_subscription(s);
write_stringz(&c->out, "R");
write_stringz(&c->out, token);
write_errno(&c->out, err);
write_stream(&c->out, MARKER_EOM);
}
示例12: command_set_win_size
static void command_set_win_size(char * token, Channel * c) {
int err = 0;
char id[256];
unsigned tid;
Terminal * term = NULL;
unsigned ws_col;
unsigned ws_row;
int changed = 0;
json_read_string(&c->inp, id, sizeof(id));
json_test_char(&c->inp, MARKER_EOA);
ws_col = json_read_ulong(&c->inp);
json_test_char(&c->inp, MARKER_EOA);
ws_row = json_read_ulong(&c->inp);
json_test_char(&c->inp, MARKER_EOA);
json_test_char(&c->inp, MARKER_EOM);
tid = id2tid(id);
if (tid == 0 || (term = find_terminal(tid)) == NULL) {
err = ERR_INV_CONTEXT;
}
else if (set_process_tty_win_size(term->prs, ws_col, ws_row, &changed) < 0) {
err = errno;
}
if (changed) send_event_terminal_win_size_changed(&term->bcg->out, term);
write_stringz(&c->out, "R");
write_stringz(&c->out, token);
write_errno(&c->out, err);
write_stream(&c->out, MARKER_EOM);
}
示例13: port_server_cmd_create
static void port_server_cmd_create(char * token, Channel * c) {
int err = 0;
PortRedirectionInfo * port = loc_alloc_zero(sizeof(PortRedirectionInfo));
PortServer * server;
json_read_struct(&c->inp, read_port_server_property, port);
if (read_stream(&c->inp) != 0) exception(ERR_JSON_SYNTAX);
if (read_stream(&c->inp) != MARKER_EOM) exception(ERR_JSON_SYNTAX);
/* In case the current channel is a proxy (value-add), use the
* target channel.
*/
port->c = proxy_get_target_channel(c);
if (port->c == NULL) port->c = c;
server = create_port_redirection(port);
if (server == NULL) err = errno;
write_stringz(&c->out, "R");
write_stringz(&c->out, token);
write_errno(&c->out, err);
if (err) write_stringz(&c->out, "null");
else {
write_port_server_info(&c->out, server);
write_stream(&c->out, 0);
}
write_stream(&c->out, MARKER_EOM);
}
示例14: command_reset_cache_client
static void command_reset_cache_client(void * x) {
CommandResetArgs * args = (CommandResetArgs *)x;
Channel * c = cache_channel();
Context * ctx = id2ctx(args->id);
OutputStream * out = &c->out;
int err = 0;
if (ctx == NULL) err = ERR_INV_CONTEXT;
else if (ctx->exited) err = ERR_ALREADY_EXITED;
if (!err) {
Context * grp = get_reset_context(ctx);
ResetInfo * rst = find_reset(grp, args->type);
if (rst == NULL) err = set_errno(ERR_OTHER, "Unsupported reset type");
else if (rst->reset(ctx, &args->params) < 0) err = errno;
}
cache_exit();
while (args->params.list != NULL) {
ResetParameter * p = args->params.list;
args->params.list = p->next;
loc_free(p->name);
loc_free(p->value);
loc_free(p);
}
write_stringz(out, "R");
write_stringz(out, args->token);
write_errno(out, err);
write_stream(out, MARKER_EOM);
}
示例15: command_open
static void command_open(char * token, Channel * c) {
char path[FILE_PATH_SIZE];
unsigned long flags = 0;
FileAttrs attrs;
int file = -1;
int err = 0;
OpenFileInfo * handle = NULL;
read_path(&c->inp, path, sizeof(path));
if (read_stream(&c->inp) != 0) exception(ERR_JSON_SYNTAX);
flags = json_read_ulong(&c->inp);
if (read_stream(&c->inp) != 0) exception(ERR_JSON_SYNTAX);
memset(&attrs, 0, sizeof(FileAttrs));
json_read_struct(&c->inp, read_file_attrs, &attrs);
if (read_stream(&c->inp) != 0) exception(ERR_JSON_SYNTAX);
if (read_stream(&c->inp) != MARKER_EOM) exception(ERR_JSON_SYNTAX);
if ((attrs.flags & ATTR_PERMISSIONS) == 0) {
attrs.permissions = 0775;
}
file = open(path, to_local_open_flags(flags), attrs.permissions);
if (file < 0) {
err = errno;
}
else {
handle = create_open_file_info(c, path, file, NULL);
}
write_stringz(&c->out, "R");
write_stringz(&c->out, token);
write_fs_errno(&c->out, err);
write_file_handle(&c->out, handle);
write_stream(&c->out, MARKER_EOM);
}