关于linux下守护进程的问题

newgoodboy 2002-06-09 05:48:24
两台linux机器希望传输22个文件,在目标机上我编写了一个守护的进程,通过它来从控制机器上接受文件,先接受文件的长度,然后接受相应的行数的内容,形成文件。现在得问题是我的目标机已经接受到了数据,但是在守护进程的目录下没有发现相应的文件。
下面是守护进程的源程序,希望高手指教。
只是临时的代码,程序健壮性没有考虑。
#include "ServerSocket.h"
#include "SocketException.h"
#include <string>
#include <fstream>
#include <error.h>
static int my_read(int fd,char *ptr){
static int read_cnt=0;
static char * read_ptr;
static char read_buf[4096];

if(read_cnt<=0){

if((read_cnt=read(fd,read_buf,sizeof(read_buf)))<0){

return(-1);
}else if(read_cnt==0)
return(0);
read_ptr=read_buf;
}
read_cnt--;
*ptr=*read_ptr++;
return(1);
}
int readLine(string & s)
{
int n,rc;
char c,*ptr;
char recvLine[1024];
s="";
ptr=recvLine;
for(n=1;n<1024;n++)
{
if((rc=my_read(0,&c))==1){
*ptr++=c;
if(c=='\n')
break;
}else if (rc==0)
{
if (n==1)
return(0);
else
break;
}else
return(-1);
}
*ptr=0;
s=recvLine;
return (n);
}

int main ( int argc, int argv[] )
{
string fileNames[22]={"Resovler.conf","Shared.conf", "Index.conf","Index1.conf","Index2.conf",
"Local.conf", "Merge.conf", "Merge1.conf" ,"Merge2.conf", "index_start.conf",
"index_start_1.conf" ,"index_start_2.conf" , "resolver_start.conf","storemanager_start_file.conf", "storemanager.conf",
"storenode.conf", "storenode1.conf", "storenode2.conf","query.conf", "query1.conf",
"query2.conf", "crawler.conf"};
int fileLens[22]={14,26,13,13,13,
72,8,8,8,1,
1,1,1,1,4,
3,3,3,3,3,
3,6};


while ( true ){
string::size_type beginPos=0;
string endString("End");
string finishString("finish\n");
string data;

/*for(int i=0;i<22;i++){
readLine(data);
cout<<data<<endl;
fileLens[i]=atoi(data.c_str());

}*/

for(int j=0;j<2;j++){
ofstream outFile(fileNames[j].c_str());
if(!outFile){
cerr<<"Cant open"<< fileNames[j];
return(-1);
}

for(int k=0;k<fileLens[j];k++){
readLine(data);
write(1,data.c_str(),data.size());
outFile.write(data.c_str(),data.size());
}
}

readLine(data);
write(1,data.c_str(),data.size());
//write(1,finishString.c_str(),finishString.size());
if(!data.compare(endString,beginPos,3)){
write(1,finishString.c_str(),finishString.size());

}

}
}

...全文
28 回复 打赏 收藏 转发到动态 举报
写回复
用AI写文章
回复
切换为时间正序
请发表友善的回复…
发表回复

19,612

社区成员

发帖
与我相关
我的任务
社区描述
系统使用、管理、维护问题。可以是Ubuntu, Fedora, Unix等等
社区管理员
  • 系统维护与使用区社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧