static void cq_comp_handler(struct ib_cq *cq, void *cq_context) { struct p9_client *client = cq_context; struct p9_trans_rdma *rdma = client->trans; int ret; struct ib_wc wc; ib_req_notify_cq(rdma->cq, IB_CQ_NEXT_COMP); while ((ret = ib_poll_cq(cq, 1, &wc)) > 0) { struct p9_rdma_context *c = (void *) (unsigned long) wc.wr_id; switch (c->wc_op) { case IB_WC_RECV: handle_recv(client, rdma, c, wc.status, wc.byte_len); up(&rdma->rq_sem); break; case IB_WC_SEND: handle_send(client, rdma, c, wc.status, wc.byte_len); up(&rdma->sq_sem); break; default: pr_err("unexpected completion type, c->wc_op=%d, wc.opcode=%d, status=%d\n", c->wc_op, wc.opcode, wc.status); break; } kfree(c); } }
/* * Handle compatibility ioctls */ static long compat_ipmi_ioctl(struct file *filep, unsigned int cmd, unsigned long arg) { struct ipmi_file_private *priv = filep->private_data; switch(cmd) { case COMPAT_IPMICTL_SEND_COMMAND: { struct ipmi_req rp; struct compat_ipmi_req r32; int retries; unsigned int retry_time_ms; if (copy_from_user(&r32, compat_ptr(arg), sizeof(r32))) return -EFAULT; get_compat_ipmi_req(&rp, &r32); mutex_lock(&priv->recv_mutex); retries = priv->default_retries; retry_time_ms = priv->default_retry_time_ms; mutex_unlock(&priv->recv_mutex); return handle_send_req(priv->user, &rp, retries, retry_time_ms); } case COMPAT_IPMICTL_SEND_COMMAND_SETTIME: { struct ipmi_req_settime sp; struct compat_ipmi_req_settime sp32; if (copy_from_user(&sp32, compat_ptr(arg), sizeof(sp32))) return -EFAULT; get_compat_ipmi_req_settime(&sp, &sp32); return handle_send_req(priv->user, &sp.req, sp.retries, sp.retry_time_ms); } case COMPAT_IPMICTL_RECEIVE_MSG: case COMPAT_IPMICTL_RECEIVE_MSG_TRUNC: { struct ipmi_recv recv64; struct compat_ipmi_recv recv32; if (copy_from_user(&recv32, compat_ptr(arg), sizeof(recv32))) return -EFAULT; get_compat_ipmi_recv(&recv64, &recv32); return handle_recv(priv, cmd == COMPAT_IPMICTL_RECEIVE_MSG_TRUNC, &recv64, copyout_recv32, compat_ptr(arg)); } default: return ipmi_ioctl(filep, cmd, arg); } }
static int ev_handler(struct mg_connection *conn, enum mg_event ev) { switch (ev) { case MG_AUTH: return MG_TRUE; case MG_REQUEST: return handle_request(conn); case MG_RECV: return handle_recv(conn); case MG_CLOSE: return handle_close(conn); default: return MG_FALSE; } }
int command_link(struct debugger_state *state, int argc, char **argv) { if (argc < 3) { state->print(state, "%s [send|recv|socket] [value|behavior|path]\n" "send a value will send a value to the link port. If you pass a file, it will be sent instead.\n" "recv [behavior] defines z80e's behavior when receiving link port data.\n" "Use 'print' to print each value, or a file name to write values to that file.\n", argv[0]); return 0; } if (strcasecmp(argv[1], "send") == 0) { return handle_send(state, argc, argv); } else if (strcasecmp(argv[1], "recv") == 0) { return handle_recv(state, argc, argv); } else if (strcasecmp(argv[1], "socket") == 0) { return handle_socket(state, argc, argv); } else { state->print(state, "Invalid operation %s", argv[1]); } return 0; }
static int event_handler(struct mg_connection *conn, enum mg_event ev) { switch (ev) { case MG_AUTH: //printf("event_handler , MG_AUTH\n"); return MG_TRUE; case MG_REQUEST: //printf("event_handler , MG_REQUEST\n"); return handle_request(conn); case MG_RECV: //printf("event_handler , MG_RECV\n"); return handle_recv(conn); case MG_CLOSE: //printf("event_handler , MG_CLOSE\n"); return handle_close(conn); default: // printf("event_handler , default\n"); return MG_FALSE; } }
void service_loop( void ) { int command = 0; pfile nf = NULL; /// Create the root file root = init_file(); if ( root == NULL ) { printf("[ERROR] Failed to create the root node\n"); return; } set_type( root, DIR ); set_name( root, "/"); while (1) { if ( recv( (char*)&command, 4 ) != 4 ) { // Failed to receive send error printf("[ERROR] Receive failed\n"); return; } switch ( command ) { /// SEND case 0x444e4553: if ( handle_send( ) == 0 ) { continue; } break; /// NDIR case 0x5249444e: if ( handle_ndir( ) == 0 ) { continue; } break; /// RECV case 0x56434552: if ( handle_recv() == 0 ) { continue; } break; /// STOP case 0x504f5453: printf("[INFO] Terminating\n"); _terminate(0); break; /// PRNT case 0x544e5250: printf("[INFO] Listing files\n"); handle_prnt( root, "" ); break; /// REPO case 0x4f504552: handle_repo( ); break; default: printf("[ERROR] Invalid command: $x\n", command); break; }; } return; }
static long ipmi_ioctl(struct file *file, unsigned int cmd, unsigned long data) { int rv = -EINVAL; struct ipmi_file_private *priv = file->private_data; void __user *arg = (void __user *)data; switch (cmd) { case IPMICTL_SEND_COMMAND: { struct ipmi_req req; int retries; unsigned int retry_time_ms; if (copy_from_user(&req, arg, sizeof(req))) { rv = -EFAULT; break; } mutex_lock(&priv->recv_mutex); retries = priv->default_retries; retry_time_ms = priv->default_retry_time_ms; mutex_unlock(&priv->recv_mutex); rv = handle_send_req(priv->user, &req, retries, retry_time_ms); break; } case IPMICTL_SEND_COMMAND_SETTIME: { struct ipmi_req_settime req; if (copy_from_user(&req, arg, sizeof(req))) { rv = -EFAULT; break; } rv = handle_send_req(priv->user, &req.req, req.retries, req.retry_time_ms); break; } case IPMICTL_RECEIVE_MSG: case IPMICTL_RECEIVE_MSG_TRUNC: { struct ipmi_recv rsp; if (copy_from_user(&rsp, arg, sizeof(rsp))) rv = -EFAULT; else rv = handle_recv(priv, cmd == IPMICTL_RECEIVE_MSG_TRUNC, &rsp, copyout_recv, arg); break; } case IPMICTL_REGISTER_FOR_CMD: { struct ipmi_cmdspec val; if (copy_from_user(&val, arg, sizeof(val))) { rv = -EFAULT; break; } rv = ipmi_register_for_cmd(priv->user, val.netfn, val.cmd, IPMI_CHAN_ALL); break; } case IPMICTL_UNREGISTER_FOR_CMD: { struct ipmi_cmdspec val; if (copy_from_user(&val, arg, sizeof(val))) { rv = -EFAULT; break; } rv = ipmi_unregister_for_cmd(priv->user, val.netfn, val.cmd, IPMI_CHAN_ALL); break; } case IPMICTL_REGISTER_FOR_CMD_CHANS: { struct ipmi_cmdspec_chans val; if (copy_from_user(&val, arg, sizeof(val))) { rv = -EFAULT; break; } rv = ipmi_register_for_cmd(priv->user, val.netfn, val.cmd, val.chans); break; } case IPMICTL_UNREGISTER_FOR_CMD_CHANS: { struct ipmi_cmdspec_chans val; if (copy_from_user(&val, arg, sizeof(val))) { rv = -EFAULT; break; } rv = ipmi_unregister_for_cmd(priv->user, val.netfn, val.cmd, val.chans); break; } case IPMICTL_SET_GETS_EVENTS_CMD: { int val; if (copy_from_user(&val, arg, sizeof(val))) { rv = -EFAULT; break; } rv = ipmi_set_gets_events(priv->user, val); break; } /* The next four are legacy, not per-channel. */ case IPMICTL_SET_MY_ADDRESS_CMD: { unsigned int val; if (copy_from_user(&val, arg, sizeof(val))) { rv = -EFAULT; break; } rv = ipmi_set_my_address(priv->user, 0, val); break; } case IPMICTL_GET_MY_ADDRESS_CMD: { unsigned int val; unsigned char rval; rv = ipmi_get_my_address(priv->user, 0, &rval); if (rv) break; val = rval; if (copy_to_user(arg, &val, sizeof(val))) { rv = -EFAULT; break; } break; } case IPMICTL_SET_MY_LUN_CMD: { unsigned int val; if (copy_from_user(&val, arg, sizeof(val))) { rv = -EFAULT; break; } rv = ipmi_set_my_LUN(priv->user, 0, val); break; } case IPMICTL_GET_MY_LUN_CMD: { unsigned int val; unsigned char rval; rv = ipmi_get_my_LUN(priv->user, 0, &rval); if (rv) break; val = rval; if (copy_to_user(arg, &val, sizeof(val))) { rv = -EFAULT; break; } break; } case IPMICTL_SET_MY_CHANNEL_ADDRESS_CMD: { struct ipmi_channel_lun_address_set val; if (copy_from_user(&val, arg, sizeof(val))) { rv = -EFAULT; break; } return ipmi_set_my_address(priv->user, val.channel, val.value); break; } case IPMICTL_GET_MY_CHANNEL_ADDRESS_CMD: { struct ipmi_channel_lun_address_set val; if (copy_from_user(&val, arg, sizeof(val))) { rv = -EFAULT; break; } rv = ipmi_get_my_address(priv->user, val.channel, &val.value); if (rv) break; if (copy_to_user(arg, &val, sizeof(val))) { rv = -EFAULT; break; } break; } case IPMICTL_SET_MY_CHANNEL_LUN_CMD: { struct ipmi_channel_lun_address_set val; if (copy_from_user(&val, arg, sizeof(val))) { rv = -EFAULT; break; } rv = ipmi_set_my_LUN(priv->user, val.channel, val.value); break; } case IPMICTL_GET_MY_CHANNEL_LUN_CMD: { struct ipmi_channel_lun_address_set val; if (copy_from_user(&val, arg, sizeof(val))) { rv = -EFAULT; break; } rv = ipmi_get_my_LUN(priv->user, val.channel, &val.value); if (rv) break; if (copy_to_user(arg, &val, sizeof(val))) { rv = -EFAULT; break; } break; } case IPMICTL_SET_TIMING_PARMS_CMD: { struct ipmi_timing_parms parms; if (copy_from_user(&parms, arg, sizeof(parms))) { rv = -EFAULT; break; } mutex_lock(&priv->recv_mutex); priv->default_retries = parms.retries; priv->default_retry_time_ms = parms.retry_time_ms; mutex_unlock(&priv->recv_mutex); rv = 0; break; } case IPMICTL_GET_TIMING_PARMS_CMD: { struct ipmi_timing_parms parms; mutex_lock(&priv->recv_mutex); parms.retries = priv->default_retries; parms.retry_time_ms = priv->default_retry_time_ms; mutex_unlock(&priv->recv_mutex); if (copy_to_user(arg, &parms, sizeof(parms))) { rv = -EFAULT; break; } rv = 0; break; } case IPMICTL_GET_MAINTENANCE_MODE_CMD: { int mode; mode = ipmi_get_maintenance_mode(priv->user); if (copy_to_user(arg, &mode, sizeof(mode))) { rv = -EFAULT; break; } rv = 0; break; } case IPMICTL_SET_MAINTENANCE_MODE_CMD: { int mode; if (copy_from_user(&mode, arg, sizeof(mode))) { rv = -EFAULT; break; } rv = ipmi_set_maintenance_mode(priv->user, mode); break; } default: rv = -ENOTTY; break; } return rv; }
// ikst_NotifyFunc // // Important: Any callback made here must always be in a tail // position. static void transportCallback(void *user_data, ikst_event *event) { ikss_Stream *self = (ikss_Stream*)user_data; switch (event->event) { // We will not automatically send any headers or anything, but // we do provide methods for doing that. The stream should be // ready for messaging right away. case ikst_CONNECTED: { int ret = request_recv(self); if (ret) { (self->notifyFunc)(self->user_data, ikss_IKS_ERROR, event->data0); } else { (self->notifyFunc)(self->user_data, ikss_CONNECTED, 0); } break; } // Really, if the server is behaving nicely, it should send // </stream> before EOF, and that should trigger us closing the // connection before we get the EOF. But this matters little, // getting an EOF error here should lead to the same end result. case ikst_EOF: // It is not safe for us to delete ourselves or anything, but // the client may want to do that right away upon receiving this // event. case ikst_IKS_ERROR: case ikst_PLAT_ERROR: { #if !defined(__SYMBIAN32__) if (ikst_PLAT_ERROR == event->event) { printf("transport error: %s (%d)\n", strerror(event->data0), event->data0); } #endif /* __SYMBIAN32__ */ (self->notifyFunc)(self->user_data, event->event, event->data0); break; } case ikst_WRITE_OK: { // If there is anything left to send, resume sending, // otherwise propagate the event to the client so that it // knows it can send more messages. self->send_count += event->data0; if ((self->send_count < self->send_len) || self->send_more_buf) { int ret = send_more(self); if (ret) { (self->notifyFunc)(self->user_data, ikss_IKS_ERROR, ret); } } else { (self->notifyFunc)(self->user_data, ikss_SENT, 0); } break; } case ikst_READ_OK: { // Pass the read data to the parser, and if it was // syntactically fine, then put in another recv request. int ret = (handle_recv (self, event->data0) || request_recv (self)); if (ret) { (self->notifyFunc)(self->user_data, ikss_IKS_ERROR, ret); } break; } default: { assert(0); break; } } }
/* * 功 能:处理与客户端的连接 * 参 数:无 * 返回值:无 */ int do_run() { FILE * fout = fopen(SERVER_DATA_FILE, "a+"); if (NULL == fout) { HACK_DEBUG(9, "open file %s failed, %s\n", SERVER_DATA_FILE, strerror(errno)); return -1; } int server_sockfd, client_sockfd; int server_len, client_len, ret; struct sockaddr_in server_address; struct sockaddr_in client_address; fd_set readfds, testfds; /* new socket */ server_sockfd = socket(AF_INET, SOCK_STREAM, 0); if(-1 == server_sockfd) { HACK_DEBUG(9, "error getting socket, %s", strerror(errno)); return -2; } /* bind address */ server_address.sin_family = AF_INET; server_address.sin_addr.s_addr = htonl(INADDR_ANY); server_address.sin_port = htons(9876); server_len = sizeof(server_address); ret = bind(server_sockfd, (const struct sockaddr *)&server_address, server_len); if(0 > ret) { HACK_DEBUG(9, "cannot bind socket, %s", strerror(errno)); close(server_sockfd); return -3; } /* listen...... */ listen(server_sockfd, SOCKET_LISTEN_MAXNUM); FD_ZERO(&readfds); FD_SET(server_sockfd, &readfds); while (1) { HACK_DEBUG(0, "server waitting......\n"); testfds = readfds; ret = select(FD_SETSIZE, &testfds, NULL, NULL, NULL); if (ret < 1) perror("select error : "); HACK_DEBUG(0, "ret=%d\n", ret); int fd; for (fd = 0; fd < FD_SETSIZE; fd++) { if (!FD_ISSET(fd, &testfds)) continue; if (fd == server_sockfd) { client_len = sizeof(struct sockaddr_in); client_sockfd = accept(server_sockfd, (struct sockaddr *)&client_address, &client_len); FD_SET(client_sockfd, &readfds); HACK_DEBUG(0, "add client on fd[%d] with ip=%x port=%d\n", client_sockfd, client_address.sin_addr.s_addr, ntohs(client_address.sin_port)); }else { int ret = handle_recv(fd, fout); if (-1 == ret) { FD_CLR(fd, &readfds); HACK_DEBUG(0, "delete client on fd[%d]\n", fd); } } } } close(server_sockfd); fclose(fout); return 0; }