/*i/o 2 files *READ 1x struct request_data_t *WRITE 1x char, reply *READ 1x char is_complete flag, if 0 *WRITE 1x int, nodeid *READ 1x char, reply *WRITE 1x size_t, array_len *READ 1x char, reply *WRITE array_len x HistogramArrayItem, histograms array * @return 1-should receive again, 0-complete request - it should not be listen again*/ int read_requests_write_detailed_histograms( int fdr, int fdw, int nodeid, const BigArrayPtr source_array, int array_len){ int is_complete = 0; do { WRITE_FMT_LOG(LOG_DEBUG, "Reading from file %d detailed histograms request\n", fdr );fflush(0); /*receive data needed to create histogram using step=1, actually requested histogram should contains array items range*/ struct request_data_t received_histogram_request; read_channel(fdr, (char*) &received_histogram_request, sizeof(struct request_data_t) ); read_channel(fdr, (char*) &is_complete, sizeof(is_complete) ); int histogram_len = 0; //set to our offset, check it int offset = min(received_histogram_request.first_item_index, array_len-1 ); int requested_length = received_histogram_request.last_item_index - received_histogram_request.first_item_index; requested_length = min( requested_length, array_len - offset ); HistogramArrayPtr histogram = alloc_histogram_array_get_len( source_array, offset, requested_length, 1, &histogram_len ); size_t sending_array_len = histogram_len; /*Response to request, entire reply contains requested detailed histogram*/ write_channel(fdw, (const char*)&nodeid, sizeof(int) ); write_channel(fdw, (const char*)&sending_array_len, sizeof(size_t) ); write_channel(fdw, (const char*)histogram, histogram_len*sizeof(HistogramArrayItem) ); free( histogram ); WRITE_FMT_LOG(LOG_DEBUG, "histograms wrote into file %d\n", fdw ); }while(!is_complete); return is_complete; }
int exec_shell_script(char* fname, LIBSSH2_SESSION *session, LIBSSH2_CHANNEL **channel, int sock) { int rc; if((rc=open_shell(session, channel, sock)) <0) return -1; FILE* cmdfile = fopen(fname, "r"); if(cmdfile == NULL) { printf("open file %s errno: %s\n", fname, strerror(errno)); exit(errno); } char buf[BUFSIZ]; int i; do { fgets(buf, BUFSIZ, cmdfile); if(feof(cmdfile) == 1) break; write_channel(buf, session, *channel, sock); }while(!feof(cmdfile)); strncpy(buf, "\nexit\n", 6); write_channel(buf, session, *channel, sock); read_channel(session, *channel, sock); fclose(cmdfile); // while((rc = libssh2_channel_close(*channel)) == LIBSSH2_ERROR_EAGAIN) waitsocket(sock, session); rc = libssh2_channel_close(*channel); return rc; }
/*writing data * 1x struct packet_data_t[EPACKET_HISTOGRAM] * array_len x HistogramArrayItem*/ void write_histogram( int fdw, const struct Histogram *histogram ){ size_t array_size = sizeof(HistogramArrayItem)*(histogram->array_len); struct packet_data_t t; t.type = EPACKET_HISTOGRAM; t.src_nodeid = histogram->src_nodeid; t.size = array_size; WRITE_FMT_LOG(LOG_DEBUG, "write histogram: fd=%d, size=%d, type=%d, src_nodeid=%d\n", fdw, (int)t.size, t.type, t.src_nodeid); /*writing to pipeline whole packet*/ write_channel(fdw, (const char*)&t, sizeof(t)); write_channel(fdw, (const char*)histogram->array, array_size); WRITE_LOG(LOG_DEBUG, "write histogram OK\n"); }
bool Pwm_stm32::set_pulse_width_us(uint16_t pulse_us) { duty_cyle_ = pulse_us; write_channel(); return true; }
bool Pwm_stm32::set_period_us(uint16_t period_us) { // WARNING this affect the period of the TIMER not only the specific channel period_ = period_us; write_channel(); return true; }
/*i/o *WRITE 1x struct packet_data_t [EPACKET_RANGE] *WRITE array_len x BigArrayItem, array*/ void write_sorted_ranges( int fdw, const struct request_data_t* sequence, const BigArrayPtr src_array ){ const int array_len = sequence->last_item_index - sequence->first_item_index + 1; const BigArrayPtr array = src_array+sequence->first_item_index; WRITE_FMT_LOG(LOG_DEBUG, "Sending array_len=%d; min=%u, max=%u\n", array_len, array[0], array[array_len-1]); /*write header*/ struct packet_data_t t; t.size = array_len*sizeof(BigArrayItem); t.type = EPACKET_RANGE; WRITE_FMT_LOG(LOG_DEBUG, "writing to %d: size=%d, type=%d (EPACKET_RANGE)\n", fdw, (int)t.size, t.type ); WRITE_FMT_LOG(LOG_DEBUG, "sizeof(struct packet_data_t)=%d\n", (int)sizeof(struct packet_data_t)); write_channel(fdw, (const char*) &t, sizeof(struct packet_data_t)); write_channel(fdw, (const char*) array, t.size); write_channel(fdw, (const char*) "1", 1); //send at last small data WRITE_LOG(LOG_DEBUG, "Reply from receiver OK;\n"); }
/*writing data: * 1x struct sort_result*/ void write_sort_result( int fdw, int nodeid, BigArrayPtr sorted_array, int len ){ if ( !len ) return; uint32_t sorted_crc = array_crc( sorted_array, ARRAY_ITEMS_COUNT ); WRITE_FMT_LOG(LOG_DEBUG, "[%d] send_sort_result: min=%u, max=%u, crc=%u\n", nodeid, sorted_array[0], sorted_array[len-1], sorted_crc ); struct sort_result result; result.nodeid = nodeid; result.min = sorted_array[0]; result.max = sorted_array[len-1]; result.crc = sorted_crc; write_channel(fdw, (const char*)&result, sizeof(result)); }
int PutRowILBM( PicInfo *pic ) { int i, size, nchans, nchplanes; nchans = ( pic->bmhd.nPlanes == 24 ) ? 3 : 1; nchplanes = ( nchans == 3 ) ? 8 : pic->bmhd.nPlanes; for ( i = 0; i < nchans; i++ ) { size = write_channel( pic->fp, pic->rgb[ i ], pic->buf, pic->body, pic->rowsize, nchplanes ); if ( !size ) return FALSE; } return TRUE; }
static void handle2 (char *h) { if (h[0]) { if (!strcmp (h, "NONE")) h[0] = '\0'; /* Inform @'s and %'s of the handle change */ sprintf (msg_buf, " * %s/%s is now %s/%s", cur_slot->acct.id, cur_slot->acct.handle, cur_slot->acct.id, h); strcpy (cur_slot->acct.handle, h); write_user (&cur_slot->acct); write_channel (msg_buf, cur_slot->acct.chan, PA_MSG); } setproc (sendpub, MAXMSG, 0); }
void *client(void *arg) { channel_t channel = (channel_t)arg; uint32_t major_stat; uint32_t minor_stat; uint32_t rflags; uint32_t inout_gssd_flags; gssd_cred cred_handle = (gssd_cred) (uintptr_t)GSS_C_NO_CREDENTIAL; gssd_ctx gss_context = (gssd_ctx) (uintptr_t)GSS_C_NO_CONTEXT; kern_return_t kr; int gss_error = 0; int retry_count = 0; char display_name[128]; do { if (read_channel(1, channel)) { Log("Bad read from server\n"); return (NULL); } if (verbose) Debug("Calling mach_gss_init_sec_context from %p\n", (void *) pthread_self()); deallocate(channel->ctoken, channel->ctokenCnt); channel->ctoken = (gssd_byte_buffer)GSS_C_NO_BUFFER; channel->ctokenCnt = 0; retry: switch (version) { case 0: case 1: kr = mach_gss_init_sec_context( client_mp, mech, channel->stoken, channel->stokenCnt, uid, principal, svcname, flags, gssd_flags, &gss_context, &cred_handle, &rflags, &channel->clnt_skey, &channel->clnt_skeyCnt, &channel->ctoken, &channel->ctokenCnt, &major_stat, &minor_stat); break; case 2: inout_gssd_flags = gssd_flags; kr = mach_gss_init_sec_context_v2( client_mp, mech, channel->stoken, channel->stokenCnt, uid, clientp.nt, clientp.name, clientp.len, targetp.nt, targetp.name, targetp.len, flags, &inout_gssd_flags, &gss_context, &cred_handle, &rflags, &channel->clnt_skey, &channel->clnt_skeyCnt, &channel->ctoken, &channel->ctokenCnt, display_name, &major_stat, &minor_stat); if (verbose && kr == KERN_SUCCESS && major_stat == GSS_S_COMPLETE) Debug("Got client identity of '%s'\n", display_name); break; default: Log("Unsupported version %d\n", version); exit(1); break; } if (kr != KERN_SUCCESS) { OSAtomicIncrement32(&server_errors); Log("gsstest client: %s\n", mach_error_string(kr)); if (exitonerror) exit(1); if (kr == MIG_SERVER_DIED) { OSAtomicIncrement32(&server_deaths); if (gss_context == (uint32_t)(uintptr_t)GSS_C_NO_CONTEXT && retry_count < max_retries) { retry_count++; goto retry; } } channel->failure = 1; write_channel(1, channel); return (NULL); } gss_error = (major_stat != GSS_S_COMPLETE && major_stat != GSS_S_CONTINUE_NEEDED); if (verbose > 1) { Debug("\tcred = 0x%0x\n", (int) cred_handle); Debug("\tclnt_gss_context = 0x%0x\n", (int) gss_context); Debug("\ttokenCnt = %d\n", (int) channel->ctokenCnt); if (verbose > 2) HexDump((char *) channel->ctoken, (uint32_t) channel->ctokenCnt); } channel->failure = gss_error; write_channel(1, channel); } while (major_stat == GSS_S_CONTINUE_NEEDED); if (gss_error) { OSAtomicIncrement32(&gss_init_errors); Log("mach_gss_int_sec_context: %#K %#k\n", major_stat, mechtab[mech], minor_stat); } close_channel(1, channel); return (NULL); }
void CLibssh2::upload(const std::string& local_filepath, const std::string& remote_filepath, int* num_bytes) throw (utils::CException, sys::CSyscallException) { int local_fd = -1; LIBSSH2_CHANNEL* channel = NULL; try { struct stat fileinfo; local_fd = open(local_filepath.c_str(), O_RDONLY); if (-1 == local_fd) { THROW_SYSCALL_EXCEPTION("open failed", errno, "open"); } if (-1 == fstat(local_fd, &fileinfo)) { THROW_SYSCALL_EXCEPTION( utils::CStringUtils::format_string( "stat %s failed", local_filepath.c_str()), errno, "stat"); } if (0 == fileinfo.st_size) { // 阻止空文件 THROW_EXCEPTION("empty file", -1); } channel = static_cast<LIBSSH2_CHANNEL*>(open_scp_write_channel( remote_filepath, fileinfo.st_mode, fileinfo.st_size, fileinfo.st_mtime, fileinfo.st_atime)); *num_bytes = 0; for (;;) { char buffer[4096]; int bytes = read(local_fd, buffer, sizeof(buffer)); if (-1 == bytes) { THROW_SYSCALL_EXCEPTION("read failed", errno, "read"); } else if (0 == bytes) { break; } else { *num_bytes += bytes; write_channel(channel, buffer, bytes); } } libssh2_channel_free(channel); close(local_fd); } catch (...) { if (channel != NULL) libssh2_channel_free(channel); if (local_fd != -1) close(local_fd); throw; } }
//,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; }
void sendpub (char *text) { write_log (text); write_channel (text, cur_slot->acct.chan, USR_MSG); }
/*writing data *WRITE 1x uint32_t, crc*/ void write_crc(int fdw, uint32_t crc ){ write_channel(fdw, (const char*)&crc, sizeof(crc) ); }
int main (int argc, char *argv[]) { char tmp; struct vmodttl_config conf; int val; int i; printf(" ______________________________________ \n"); printf(" | | \n"); printf(" | VMOD-TTL Testing program | \n"); printf(" |______________________________________| \n"); printf(" | | \n"); printf(" | Created by: Samuel I. Gonsalvez | \n"); printf(" | Email: [email protected] | \n"); printf(" |______________________________________| \n"); if (argc == 2) { device = atoi(argv[1]); } else { printf("\n Please use: tstlibttl <lun_of_the_device>.\n"); exit(-1); } if(vmodttl_open (device) < 0) { perror("open failed"); return -1; } printf("\n Port configuration \n"); printf("\n Channel A [ (0) Input - (1) Output]: \n"); scanf("%d", &val); conf.dir_a = val; conf.mode_a = 0; /* It's not open collector */ printf("\n Channel B [ (0) Input - (1) Output]: \n"); scanf("%d", &val); conf.dir_b = val; conf.mode_b = 0; /* It's not open collector */ conf.mode_c = 0; /* It's not open collector */ printf("\n Up time of the pulse in the data strobe (useg): \n"); scanf("%d", &val); conf.us_pulse = val; printf("\n In all the channels: [ (0) Non-inverting Logic - (1) Inverting logic]: \n"); scanf("%d", &val); conf.inverting_logic = val; conf.pattern_mode_a = AND; conf.pattern_mode_b = OR; for(i = 0; i< NUM_BITS; i++) { conf.conf_pattern_a[i] = OFF; conf.conf_pattern_b[i] = OFF; } if (vmodttl_io_config(device, conf) < 0) exit(-1); do{ if(tmp != '\n'){ printf("\n **** OPTIONS ****\n\n"); printf(" a) Write channel.\n"); printf(" b) Read channel.\n"); printf(" Press \'q\' to exit...\n"); } scanf("%c", &tmp); switch(tmp){ case 'a': write_channel(device); break; case 'b': read_channel(device); break; case 'q': printf(" Exiting...\n"); break; default: break; } }while(tmp != 'q'); conf.pattern_mode_a = 1; conf.mode_a = 1; conf.dir_a = 1; if(vmodttl_io_chan_config(device, 0, conf)) exit(-1); if(vmodttl_read_config(device, &conf)) exit(-1); printf("\n\n ------------------------------- \n"); printf("\n\n I/O Config used! \n"); printf(" ------------------------------- \n"); printf(" dir a: %d mode a: %d \n", conf.dir_a, conf.mode_a); printf(" dir b: %d mode b: %d \n", conf.dir_b, conf.mode_b); printf(" mode c: %d \n", conf.mode_c); printf(" us_pulse: %d inverting_logic: %d\n", conf.us_pulse, conf.inverting_logic); printf(" pattern mode A: %d pattern mode B: %d\n", conf.pattern_mode_a, conf.pattern_mode_b); printf(" port A: %d/%d/%d/%d/%d/%d/%d/%d port B: %d/%d/%d/%d/%d/%d/%d/%d \n", conf.conf_pattern_a[0], conf.conf_pattern_a[1], conf.conf_pattern_a[2], conf.conf_pattern_a[3], conf.conf_pattern_a[4], conf.conf_pattern_a[5], conf.conf_pattern_a[6], conf.conf_pattern_a[7], conf.conf_pattern_b[0], conf.conf_pattern_b[1], conf.conf_pattern_b[2], conf.conf_pattern_b[3], conf.conf_pattern_b[4], conf.conf_pattern_b[5], conf.conf_pattern_b[6], conf.conf_pattern_b[7] ); printf("\n\n ------------------------------- \n"); vmodttl_close(device); return 0; }