English 中文(简体)
利用袖珍发送数据
原标题:execlp stops using socket to send the data

i m creating a program to process some data remote. So i use something like

cat file ./client - “Actionneip” -p “port” -c “command”

i can use the command as "base64 -d | tar -zvt" if i want to get the list inside my tar file. I have those objects;

Sock.. is an object that implements the C socket. RCVBUFSIZE = 2000 and the size i use to send and get data pid to know if i m the child or the parent process

To do that i i m using the pipe and fork. the basic structure is:

int fd[2];
pipe(fd);
if((pid=fork()) == -1) exit(-1);
if(pid == 0)
{
 while((recvMsgSize = sock->recv(echoBuffer, RCVBUFSIZE)){
  write(fd[1], echoBuffer, recvMsgSize);
 }
}
else pipeback(fd,sock)

So i can get the data and send from the parent to the child. The client read from the stdin and send through the socket and the server read through the socket

问题在于管道。

void pipeback(int *fdRef, TCPSocket *sock){
 char *buffer = new char[2000];
 int size;
 close(fdRef[1]);
 dup2(fdRef[0], 0);
 close(fdrEf[0]);
 pipe(fout)
 if((pid = fork()) == -1)exit(-1);
 if(pid ==0){
  close(fout[0]);
  dup2(fout[1], 1);
  close(fout[1]);
  execlp("bash", "bash", "-c", "base64", NULL);
 }
 else{
  close(fout[1]);
  while((size = read(fout[0], buffer, 2000)) > 0){
   sock->send(buffer, size);
   write(fileno(stdout), buffer, size);
  }
 }
}

the problem is the line "execlp("bash", "bash", "-c", "base64", NULL);" if i use the cat on the fourth argument it works, if i use one ls -lahtr is shows me the files on the folder, so, works like a charm. BUT, when i use base64 or uuencode... probably other commands it stops on the read line, and stops, dies, i used strace and the gdb to see what is happening. I don t know what i need to do to debug this process. So i created an separate program, only to read from the stdin and use the pipe to process on base64 or uuencode using the bash. It works, i thing it is something with the socket or the time, but i dont have any ideas. Sorry, but my English is not that gooood... XD. Thanks for everything

注:

我使用了race子,在使用基底64时,我注意到了 stop,然后试图从粉刷中读(已经停止)。

Someone know how i can solve that?

最佳回答

The problem was

I send data and try to recv on the same block of code. So i m now using the select to wait until i have some data.

问题回答

暂无回答




相关问题
Undefined reference

I m getting this linker error. I know a way around it, but it s bugging me because another part of the project s linking fine and it s designed almost identically. First, I have namespace LCD. Then I ...

C++ Equivalent of Tidy

Is there an equivalent to tidy for HTML code for C++? I have searched on the internet, but I find nothing but C++ wrappers for tidy, etc... I think the keyword tidy is what has me hung up. I am ...

Template Classes in C++ ... a required skill set?

I m new to C++ and am wondering how much time I should invest in learning how to implement template classes. Are they widely used in industry, or is this something I should move through quickly?

Print possible strings created from a Number

Given a 10 digit Telephone Number, we have to print all possible strings created from that. The mapping of the numbers is the one as exactly on a phone s keypad. i.e. for 1,0-> No Letter for 2->...

typedef ing STL wstring

Why is it when i do the following i get errors when relating to with wchar_t? namespace Foo { typedef std::wstring String; } Now i declare all my strings as Foo::String through out the program, ...

C# Marshal / Pinvoke CBitmap?

I cannot figure out how to marshal a C++ CBitmap to a C# Bitmap or Image class. My import looks like this: [DllImport(@"test.dll", CharSet = CharSet.Unicode)] public static extern IntPtr ...

Window iconification status via Xlib

Is it possible to check with the means of pure X11/Xlib only whether the given window is iconified/minimized, and, if it is, how?

热门标签