static void munger_test (handle_state h_s, offset_state offset_s, ptr_state ptr1_s, len_state len1_s, ptr_state ptr2_s, len_state len2_s) { Handle h; LONGINT offset; Ptr ptr1; LONGINT len1; Ptr ptr2; LONGINT len2; LONGINT retval; LONGINT d0; h = new_handle (h_s); offset = new_offset (offset_s, GetHandleSize (h)); ptr1 = new_ptr (ptr1_s); len1 = new_len (len1_s); ptr2 = new_ptr (ptr2_s); len2 = new_len (len2_s); dump_handle (h); retval = Munger_invoker (h, offset, ptr1, len1, ptr2, len2, &d0); dump_handle (h); dump_retval_d0 (retval, d0); if (h_s >= handle_nil_master) DisposeHandle (h); }
handle_t *journal_start(journal_t *journal, int nblocks) { handle_t *handle = journal_current_handle(); int err; if (!journal) return ERR_PTR(-EROFS); if (handle) { J_ASSERT(handle->h_transaction->t_journal == journal); handle->h_ref++; return handle; } handle = new_handle(nblocks); if (!handle) return ERR_PTR(-ENOMEM); current->journal_info = handle; err = start_this_handle(journal, handle); if (err < 0) { jbd_free_handle(handle); current->journal_info = NULL; handle = ERR_PTR(err); goto out; } out: return handle; }
int KSG_Service_Acceptor::handle_input(ACE_HANDLE fd /* = ACE_INVALID_HANDLE */) { KSG_Service_Handler *handle = new_handle(); if(!handle) { ACE_DEBUG((LM_ERROR,"创建Reactor句柄失败")); return 0; } handle->set_handle(fd); if(acceptor_.accept(handle->peer())==-1) { //free_handle(handle); handle->handle_close(); return 0; } else { handle->scheduler(this->schd_); if(handle->open() == -1) { handle->handle_close(); return 0; } else { ACE_INET_Addr peer_addr; handle->peer().get_remote_addr(peer_addr); ACE_DEBUG((LM_DEBUG,"接收新的连接请求[%s]",peer_addr.get_host_addr())); int val; ACE::record_and_set_non_blocking_mode(handle->peer().get_handle(),val); return 0; } } }
/* * Does all of the open operation with the exception of assigning a file * descriptor to the file object. */ FileHandle * open_file(Process *p, const char *path, uint32_t flags) { /* * Something like this needs to go here: * * Directory *dir = resolvePath(p, path); * char *filename = basename(path); * Inode *inode = directory_get(dir, filename); * * Otherwise, we only have 1-level directories. * FIXME: Need to check what type of inode was returned when we add multilevel * directory support. */ Inode *inode = directory_get(p->cwd, path); if (inode == NULL && flags & O_CREAT) { inode = new_inode(); directory_insert(p->cwd, path, inode); inode_inc_link_ref(inode); } if (inode == NULL) panic("No O_CREAT flag and file not found."); return new_handle(inode); }
/** @brief Creates an array of the specified size in main RAM. If the second argument is provided, the buffer is initialized with data from that pointer. * * @param size_in_bytes Number of bytes to allocate * @param host_ptr Pointer to data which will be copied to the new array. Must point to at least 'size_in_bytes' bytes of data. * */ inline handle_type memory_create(vcl_size_t size_in_bytes, const void * host_ptr = NULL) { #if defined(VIENNACL_WITH_AVX2) || defined(VIENNACL_WITH_AVX) # ifdef VIENNACL_WITH_POSIX_MEMALIGN if (!host_ptr) { void *mem_ptr; if(posix_memalign(&mem_ptr, 32, size_in_bytes)) { std::bad_alloc exception; throw exception; } return handle_type(reinterpret_cast<char*>(mem_ptr), detail::array_deleter<char>()); } void *mem_ptr; if(posix_memalign(&mem_ptr, 32, size_in_bytes)) { std::bad_alloc exception; throw exception; } handle_type new_handle(reinterpret_cast<char*>(mem_ptr), detail::array_deleter<char>()); # else // "Note: aligned_alloc not available on all compilers. Consider platform-specific alternatives such as posix_memalign()" => added above if (!host_ptr) return handle_type(reinterpret_cast<char*>(aligned_alloc(32, size_in_bytes)), detail::array_deleter<char>()); handle_type new_handle(reinterpret_cast<char*>(aligned_alloc(32, size_in_bytes)), detail::array_deleter<char>()); #endif #else if (!host_ptr) return handle_type(new char[size_in_bytes], detail::array_deleter<char>()); handle_type new_handle(new char[size_in_bytes], detail::array_deleter<char>()); #endif // copy data: char * raw_ptr = new_handle.get(); const char * data_ptr = static_cast<const char *>(host_ptr); #ifdef VIENNACL_WITH_OPENMP #pragma omp parallel for #endif for (long i=0; i<long(size_in_bytes); ++i) raw_ptr[i] = data_ptr[i]; return new_handle; }
void MainWindow::on_FiberTracking_clicked() { QString filename = QFileDialog::getOpenFileName( this, "Open Fib files", ui->workDir->currentText(), "Fib files (*fib.gz *.fib *nii.gz *.nii 2dseq);;All files (*)"); if (filename.isEmpty()) return; image::basic_image<float,3> I; float vs[3]; if(QFileInfo(filename).completeSuffix() == "nii" || QFileInfo(filename).completeSuffix() == "nii.gz") { gz_nifti header; if(!header.load_from_file(filename.toLocal8Bit().begin())) { QMessageBox::information(this,"Error","Invalid NIFTI format",0); return; } header.toLPS(I); std::copy(header.nif_header.pixdim+1,header.nif_header.pixdim+4,vs); } if(QFileInfo(filename).fileName() == "2dseq") { image::io::bruker_2dseq bruker_header; if(!bruker_header.load_from_file(filename.toLocal8Bit().begin())) { QMessageBox::information(this,"DSI Studio","Invalid 2dseq format",0); return; } bruker_header.get_image().swap(I); bruker_header.get_voxel_size(vs); } if(!I.empty()) { std::shared_ptr<fib_data> new_handle(new fib_data); new_handle->mat_reader.add("dimension",I.geometry().begin(),3,1); new_handle->mat_reader.add("voxel_size",vs,3,1); new_handle->mat_reader.add("image",&*I.begin(),I.size(),1); new_handle->load_from_mat(); new_handle->dir.index_name[0] = "image"; new_handle->view_item[0].name = "image"; tracking_window* new_mdi = new tracking_window(this,new_handle); new_mdi->setAttribute(Qt::WA_DeleteOnClose); new_mdi->setWindowTitle(filename); new_mdi->showNormal(); new_mdi->set_data("roi_fiber",0); new_mdi->scene.show_slice(); } else loadFib(filename); }
/// Creates a new handle which points to the index target_index HandleType add(size_t target_index) { assert(m_next_index < max_entries); assert(m_entries[m_next_index].m_active == false); m_entries[m_next_index].m_target_index = target_index; m_entries[m_next_index].m_active = true; HandleType new_handle(m_next_index); m_next_index = m_entries[m_next_index].m_next_free_index; return new_handle; }
/** @brief Creates an array of the specified size in main RAM. If the second argument is provided, the buffer is initialized with data from that pointer. * * @param size_in_bytes Number of bytes to allocate * @param host_ptr Pointer to data which will be copied to the new array. Must point to at least 'size_in_bytes' bytes of data. * */ inline handle_type memory_create(std::size_t size_in_bytes, const void * host_ptr = NULL) { if (!host_ptr) return handle_type(new char[size_in_bytes], detail::array_deleter<char>()); handle_type new_handle(new char[size_in_bytes], detail::array_deleter<char>()); // copy data: char * raw_ptr = new_handle.get(); const char * data_ptr = static_cast<const char *>(host_ptr); for (std::size_t i=0; i<size_in_bytes; ++i) raw_ptr[i] = data_ptr[i]; return new_handle; }
/** @brief Creates an array of the specified size on the CUDA device. If the second argument is provided, the buffer is initialized with data from that pointer. * * @param size_in_bytes Number of bytes to allocate * @param host_ptr Pointer to data which will be copied to the new array. Must point to at least 'size_in_bytes' bytes of data. * */ inline handle_type memory_create(std::size_t size_in_bytes, const void * host_ptr = NULL) { void * dev_ptr = NULL; VIENNACL_CUDA_ERROR_CHECK( cudaMalloc(&dev_ptr, size_in_bytes) ); //std::cout << "Allocated new dev_ptr " << dev_ptr << " of size " << size_in_bytes << std::endl; if (!host_ptr) return handle_type(reinterpret_cast<char *>(dev_ptr), detail::cuda_deleter<char>()); handle_type new_handle(reinterpret_cast<char*>(dev_ptr), detail::cuda_deleter<char>()); // copy data: //std::cout << "Filling new handle from host_ptr " << host_ptr << std::endl; cudaMemcpy(new_handle.get(), host_ptr, size_in_bytes, cudaMemcpyHostToDevice); return new_handle; }
void MainWindow::loadFib(QString filename) { std::string file_name = filename.toLocal8Bit().begin(); begin_prog("load fib"); std::shared_ptr<fib_data> new_handle(new fib_data); if (!new_handle->load_from_file(&*file_name.begin())) { if(!prog_aborted()) QMessageBox::information(this,"error",new_handle->error_msg.c_str(),0); return; } tracking_window* new_mdi = new tracking_window(this,new_handle); new_mdi->setAttribute(Qt::WA_DeleteOnClose); new_mdi->setWindowTitle(filename); new_mdi->showNormal(); addFib(filename); add_work_dir(QFileInfo(filename).absolutePath()); QDir::setCurrent(QFileInfo(filename).absolutePath()); }
/* handler creator - entry point ! */ static tvi_handle_t *tvi_init_bsdbt848(tv_param_t* tv_param) { char* sep ; tvi_handle_t* tvh; priv_t* priv; tvh=new_handle(); if(!tvh) return NULL; priv=(priv_t*)tvh->priv; /* if user needs to specify both /dev/bktr<n> and /dev/tuner<n> it can do this with "-tv device=/dev/bktr1,/dev/tuner1" */ /* set video device name */ if (!tv_param->device) { priv->btdev = strdup("/dev/bktr0"); priv->tunerdev = strdup("/dev/tuner0"); } else { sep = strchr(tv_param->device,','); priv->btdev = strdup(tv_param->device); if(sep) { // tuner device is also passed priv->tunerdev = strdup(sep+1); priv->btdev[sep - tv_param->device] = 0; } else { priv->tunerdev = strdup("/dev/tuner0"); } } /* set audio device name */ if (!tv_param->adevice) #ifdef USE_SUN_AUDIO priv->dspdev = strdup("/dev/sound"); #else priv->dspdev = strdup("/dev/dsp"); #endif else
handle * dialparse(char *address) { handle * pointer; pointer = NULL; char *tempaddress, *realaddress; tempaddress = strdup(address); realaddress = tempaddress; char *protocol; protocol = strsep(&tempaddress, "!"); if (protocol == '\0' || protocol == NULL) { printf("%s\n", strerror(22)); return NULL; } size_t structsize = sizeof(struct dialparse_v1); printf("protocol = %s\n", protocol); size_t protocolsize = strlen(protocol) + 1; if (protocolsize >= 4) { string dialparse_type; dialparse_type.text = "com.googlecode.evoke.dialparse.v1.0"; dialparse_type.length = strlen(dialparse_type.text) + 1; /* These types are either ips, or names that resolve to ips. */ if (strncmp("net", protocol,4) == 0 || strncmp("tcp", protocol, 4) == 0 || strncmp("udp",protocol,4) == 0 || strncmp("sctp",protocol,5) == 0) { char *host; host = strsep(&tempaddress, "!"); char *port; port = strsep(&tempaddress, "!"); if (host == '\0') { printf("%s\n", strerror(22)); return NULL; } printf("host = %s\n", host); size_t portsize = 0; if (port != '\0') { portsize = strlen(port) + 1; printf("port = %s\n", port); } size_t hostsize = strlen(host) + 1; size_t totalsize = structsize + protocolsize + hostsize + portsize; pointer = new_handle(totalsize, dialparse_type); struct dialparse_v1 * temp; temp = pointer->data; temp->protocol.text = (char *) ((size_t) temp + structsize); temp->protocol.length = protocolsize; strncpy(temp->protocol.text, protocol, protocolsize); temp->host.text = (char *) ((size_t) temp + structsize + protocolsize); temp->host.length = hostsize; strncpy(temp->host.text, host, hostsize); temp->port.text = NULL; temp->port.length = 0; if (port != '\0') { temp->port.text = (char *) ((size_t) temp + structsize + protocolsize + hostsize); temp->port.length = portsize; strncpy(temp->port.text, port, portsize); } } } free(realaddress); return pointer; }
handle * announce(char *address) { #define SOCK_MAX 128 handle * ap = NULL; handle * tempfd = NULL; struct sockaddr_in bind_address; struct hostent *bind_host; ap = dialparse(address); if (error(ap)) { return NULL; } struct dialparse_v1 * localaddress = ap->data; if (localaddress->port.text == NULL) { return NULL; } string fdlist_type; fdlist_type.text = "com.googlecode.evoke.fdlist.v1.0"; fdlist_type.length = strlen(fdlist_type.text) + 1; struct addrinfo hints, *res, *res0; int retval; int socklist[SOCK_MAX]; int nsocklist[SOCK_MAX]; int nsock; const char *cause = NULL; memset(&hints, 0, sizeof(hints)); hints.ai_family = PF_UNSPEC; hints.ai_flags = AI_PASSIVE; hints.ai_socktype = SOCK_STREAM; hints.ai_protocol = IPPROTO_TCP; if (localaddress->protocol.length >= 4) { if (strncmp(localaddress->protocol.text, "udp", 4) == 0) { hints.ai_socktype = SOCK_DGRAM; hints.ai_protocol = IPPROTO_UDP; } else if (strncmp(localaddress->protocol.text, "tcp", 4) == 0) { hints.ai_socktype = SOCK_STREAM; hints.ai_protocol = IPPROTO_TCP; } else if (strncmp(localaddress->protocol.text, "sctp", 5) == 0) { hints.ai_socktype = SOCK_STREAM; hints.ai_protocol = IPPROTO_SCTP; } else if (strncmp(localaddress->protocol.text, "unix", 4) == 0) { hints.ai_family = PF_UNIX; hints.ai_socktype = SOCK_STREAM; } else if (strncmp(localaddress->protocol.text, "net", 4) == 0) { hints.ai_socktype = SOCK_STREAM; } else { return NULL; } } else { return NULL; } if (localaddress->host.length == 2) { if (strncmp(localaddress->host.text, "*", 2) == 0) { retval = getaddrinfo(NULL, localaddress->port.text, &hints, &res0); } else { retval = getaddrinfo(localaddress->host.text, localaddress->port.text, &hints, &res0); } } else { retval = getaddrinfo(localaddress->host.text, localaddress->port.text, &hints, &res0); } if (retval) { return NULL; } nsock = 0; for (res = res0; res && nsock < SOCK_MAX; res = res->ai_next) { socklist[nsock] = socket(res->ai_family, res->ai_socktype, res->ai_protocol); if (socklist[nsock] < 0) { cause = "socket"; continue; } if (bind(socklist[nsock], res->ai_addr, res->ai_addrlen) < 0) { cause = "bind"; close(socklist[nsock]); continue; } (void) listen(socklist[nsock], 5); nsocklist[nsock] = socklist[nsock]; nsock++; } if (nsock == 0) { return NULL; } freeaddrinfo(res0); tempfd = new_handle(sizeof(int) * nsock, fdlist_type); int * fdlist; fdlist = tempfd->data; bcopy(nsocklist, fdlist, sizeof(int) * nsock); return tempfd; }
handle * dial(char *address, char *local) { handle * tempfd; char buffer[256]; handle * dp; dp = dialparse(address); if (error(dp)) { printf("%s\n", strerror(65)); return NULL; } struct dialparse_v1 * hostspec = dp->data; if (hostspec->protocol.length >= 4) { if (strncmp(hostspec->protocol.text,"net",4) == 0 || strncmp(hostspec->protocol.text,"tcp",4) == 0 || strncmp(hostspec->protocol.text,"udp",4) == 0 || strncmp(hostspec->protocol.text,"sctp",5) == 0) { string fdlist_type; fdlist_type.text = "com.googlecode.evoke.fdlist.v1.0"; fdlist_type.length = strlen(fdlist_type.text) + 1; tempfd = new_handle(sizeof(int), fdlist_type); int * fdlist; int portnum; struct servent * realport; fdlist = tempfd->data; handle * dp2; dp2 = dialparse(local); if (! error(dp2)) { struct dialparse_v1 * localaddress = dp2->data; struct sockaddr_in bind_address; struct hostent *bind_host; if (localaddress->port.text == '\0') { portnum = 0; } else { realport = getservbyname(localaddress->port.text, "tcp"); if(!realport) { portnum = strtonum(localaddress->port.text, 1, 65535, NULL); if (portnum == 0) { portnum = 0; } } else { portnum = ntohs(realport->s_port); } } bzero((char *) &bind_address, sizeof(bind_address)); bind_address.sin_family = AF_INET; if (localaddress->host.length == 2) { if (strncmp(localaddress->host.text, "*", 2) == 0) { bind_address.sin_addr.s_addr = htonl(INADDR_ANY); } else { bind_host = gethostbyname(localaddress->host.text); bcopy((char *) bind_host->h_addr, (char *) &bind_address.sin_addr.s_addr, bind_host->h_length); } } else { bind_host = gethostbyname(localaddress->host.text); bcopy((char *) bind_host->h_addr, (char *) &bind_address.sin_addr.s_addr, bind_host->h_length); } bind_address.sin_port = htons(portnum); if (bind(fdlist[0], (struct sockaddr *) &bind_address, sizeof(bind_address)) < 0) { return NULL; } } struct addrinfo hints, *res, *res0; struct sockaddr_in targetaddress; int retval; const char *cause = NULL; hints.ai_family = PF_UNSPEC; if (strncmp(hostspec->protocol.text,"udp",4) == 0) { hints.ai_socktype = SOCK_DGRAM; hints.ai_protocol = IPPROTO_UDP; } else if (strncmp(hostspec->protocol.text,"sctp",5) == 0) { hints.ai_socktype = SOCK_STREAM; hints.ai_protocol = IPPROTO_SCTP; } else if (strncmp(hostspec->protocol.text,"tcp",5) == 0) { hints.ai_socktype = SOCK_STREAM; hints.ai_protocol = IPPROTO_TCP; } else if (strncmp(hostspec->protocol.text,"unix",5) == 0) { hints.ai_socktype = SOCK_STREAM; hints.ai_family = PF_UNIX; } else { hints.ai_socktype = SOCK_STREAM; } retval = getaddrinfo(hostspec->host.text, hostspec->port.text, &hints, &res); if (retval) { return NULL; } fdlist[0] = -1; for (res = res0; res; res = res->ai_next) { fdlist[0] = socket(res->ai_family, res->ai_socktype, res->ai_protocol); if (fdlist[0] < 0) { cause = "socket"; continue; } if (connect(fdlist[0], res->ai_addr, res->ai_addrlen) < 0) { cause = "connect"; close(fdlist[0]); fdlist[0] = -1; continue; } break; } if (fdlist[0] < 0) { return NULL; } freeaddrinfo(res0); } } return tempfd; }
/* * Format editorial comment about charset mismatch */ int charset_editorial(char *charset, long int msgno, HANDLE_S **handlesp, int flags, int quality, int width, gf_io_t pc) { char *p, color[64], buf[2048]; int i, n; HANDLE_S *h = NULL; snprintf(buf, sizeof(buf), CHARSET_DISCLAIMER_1, charset ? charset : "US-ASCII"); p = &buf[strlen(buf)]; if(!(ps_global->display_charmap && strucmp(ps_global->display_charmap, "US-ASCII")) && handlesp && (flags & FM_DISPLAY) == FM_DISPLAY){ h = new_handle(handlesp); h->type = URL; h->h.url.path = cpystr("x-alpine-help:h_config_char_set"); /* * Because this filter comes after the delete_quotes filter, we need * to tell delete_quotes that this handle is used, so it won't * delete it. This is a dangerous thing. */ h->is_used = 1; if(!(flags & FM_NOCOLOR) && scroll_handle_start_color(color, sizeof(color), &n)){ for(i = 0; i < n; i++) if(p-buf < sizeof(buf)) *p++ = color[i]; } else if(F_OFF(F_SLCTBL_ITEM_NOBOLD, ps_global)){ if(p-buf+1 < sizeof(buf)){ *p++ = TAG_EMBED; *p++ = TAG_BOLDON; } } if(p-buf+1 < sizeof(buf)){ *p++ = TAG_EMBED; *p++ = TAG_HANDLE; } snprintf(p + 1, sizeof(buf)-(p+1-buf), "%d", h->key); if(p-buf < sizeof(buf)) *p = strlen(p + 1); p += (*p + 1); } sstrncpy(&p, CHARSET_DISCLAIMER_2, sizeof(buf)-(p-buf)); if(h){ /* in case it was the current selection */ if(p-buf+1 < sizeof(buf)){ *p++ = TAG_EMBED; *p++ = TAG_INVOFF; } if(scroll_handle_end_color(color, sizeof(color), &n, 0)){ for(i = 0; i < n; i++) if(p-buf < sizeof(buf)) *p++ = color[i]; } else{ if(p-buf+1 < sizeof(buf)){ *p++ = TAG_EMBED; *p++ = TAG_BOLDOFF; } } if(p-buf < sizeof(buf)) *p = '\0'; } snprintf(p, sizeof(buf)-(p-buf), CHARSET_DISCLAIMER_3, ps_global->display_charmap ? ps_global->display_charmap : "US-ASCII", (quality == CV_LOSES_SPECIAL_CHARS) ? "special " : ""); buf[sizeof(buf)-1] = '\0'; return(format_editorial(buf, width, flags, handlesp, pc) == NULL && gf_puts(NEWLINE, pc) && gf_puts(NEWLINE, pc)); }
/* handler creator - entry point ! */ static tvi_handle_t *tvi_init_dummy(tv_param_t* tv_param) { return new_handle(); }