uint32_t read(int fd, void* buf, uint32_t count) { if (!tasking_installed()) { return -1; } if (!count) { return 0; } unsigned char* chbuf = buf; memset(chbuf, 0, count); //find fd_entry corresponding to this fd task_t* current = task_with_pid(getpid()); fd_entry ent = current->fd_table[fd]; if (fd_empty(ent)) { //errno = EBADF; return -1; } //what type of file descriptor is this? //dispatch appropriately switch (ent.type) { case STD_TYPE: return std_read(current, fd, buf, count); case FILE_TYPE: return fread(buf, sizeof(char), count, (FILE*)ent.payload); case PIPE_TYPE: default: return pipe_read(fd, buf, count); } return -1; }
bool cps_api_receive_data(cps_api_channel_t handle, void *data, size_t len) { t_std_error msg_rc = STD_ERR_OK; int by = std_read(handle,data,len,true,&msg_rc); bool rc = (by==(int)len) ; if (!rc) { EV_LOG(TRACE,DSAPI,0,"CPS IPC","Was not able to read the data. (%X)",msg_rc); } return rc; }
bool cps_api_receive_header(cps_api_channel_t handle, uint32_t &op, size_t &len) { cps_msg_hdr_t hdr; t_std_error rc = STD_ERR_OK; int by = std_read(handle,&hdr,sizeof(hdr),true,&rc); if (by == 0) { return false; } if (by!=sizeof(hdr)) { EV_LOG(TRACE,DSAPI,0,"CPS IPC","Was not able to read the header."); return false; } op = hdr.operation; len = hdr.len; return true; }
cps_api_object_t cps_api_receive_object(cps_api_channel_t handle,size_t len) { if (len==0) return NULL; cps_api_object_guard og(cps_api_object_create()); t_std_error rc = STD_ERR_OK; do { if (cps_api_object_get_reserve_len(og.get()) < len) { if (!cps_api_object_reserve(og.get(),len)) break; } int by = std_read(handle,cps_api_object_array(og.get()),len,true,&rc); if (by!=(int)len) break; if (!cps_api_object_received(og.get(),len)) break; return og.release(); } while (0); EV_LOG(ERR,DSAPI,0,"CPS IPC","Was not able to read the object - MSG (%X)",rc); return NULL; }