当前位置: 首页>>代码示例>>C++>>正文


C++ IOStream::writen方法代码示例

本文整理汇总了C++中IOStream::writen方法的典型用法代码示例。如果您正苦于以下问题:C++ IOStream::writen方法的具体用法?C++ IOStream::writen怎么用?C++ IOStream::writen使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在IOStream的用法示例。


在下文中一共展示了IOStream::writen方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: fname

void
RemoteHandler::
getFileList(){

	string f_list;
	
	DIR* dirp = opendir(curr_dir.c_str());
	struct dirent *dp;	
    while ((dp = readdir(dirp)) != NULL){	
		struct stat buf;
		lstat(dp->d_name, &buf);
		string fname(dp->d_name);
		if (fname != ".")
			add_row(fname, &buf, f_list);	
	}
	f_list += "\n";
	//cout << f_list;
	int cmd_fd = c_node.command_fd;
	IOStream* ioStream;
	try{
		ioStream->writen(cmd_fd, f_list.c_str(), f_list.length());
	}
	catch(IOStream::IOException){
		cerr << "IOException! Get File List Error!\n" << flush;
		return;
	}
	return;
}
开发者ID:cftyngit,项目名称:nctuns,代码行数:28,代码来源:RemoteHandler.C

示例2: string

void
RemoteHandler::
getFile(char* filename){

	string fullpath;
	int pos = curr_dir.find_last_of("/");	
	if(pos == curr_dir.length()-1)
		fullpath = curr_dir + string(filename);
	else
		fullpath = curr_dir + "/" + string(filename);
			
	int cmd_fd  = c_node.command_fd;
	int data_fd = c_node.data_fd;
	IOStream* ioStream;
	
	FILE* fileFD = fopen(fullpath.c_str(), "r");
	long fsize = fileSize(fileFD);
	
	char reply[128];
	sprintf(reply, "size|%ld\n", fsize);
  
  try{
	ioStream->writen(cmd_fd, reply, strlen(reply));
	
	long toSend = fsize;
	long send_buf;
	long buf_size = 1024;
	char buf[buf_size];
	send_buf = min(toSend, buf_size);
	while((fread(buf, 1, send_buf, fileFD) >0) && (toSend >0)){
		ioStream->writen(data_fd, buf, send_buf);
		toSend = toSend-send_buf;
		send_buf = min(toSend, buf_size);
	}
	fclose(fileFD);	
	cout << "[File Sent!]\n" << endl << flush;
	return;
  }
  catch(IOStream::IOException){
  	cerr << "IOException! in get file, write to GUI Error!\n" << flush;
	return;
  }

}
开发者ID:cftyngit,项目名称:nctuns,代码行数:44,代码来源:RemoteHandler.C


注:本文中的IOStream::writen方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。