ProgrammingThis forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
I'm having the same problem. I can't send images through the pipe, I have no Idea what I'm doing wrong, since it works on html files. This is that section of my code:
Iramos85, are you making the client side too? Still haven't figured out, how to read the images. Right now I'm trying to read one byte at a time, and save in a file. Works a little better, but not 100% yet.
The read_body function I use, reads text/html content 100% correct. The read size is the length of the content field. Whenever it tries to read an image/jpeg, the read function actually reads all the bytes, but in my buffer/file, there's only 4 bytes? As people already have said in this thread, it shouldn't matter what kind of data, you're reading, so my read_body function would work with images. Any suggestions?
Here's the code segment for read_body(): It works beautifully with with text/html, but when I try images it writes about 4 bytes to the buffer... that's it! I've already read the header (and only the header), so only the body content resides. I could really use some help. The pointer ptr is allocated with the size of the body content, and null terminated.
Code:
int read_body(int fd, char *ptr, int length)
{
int res = 0;
int total = 0;
if(ptr != NULL)
{ //errno = 0;
while(total < length )
{
if((res = (read(fd, ptr + total, length))) < 0)
errexit("\nError readback from server. Error: %s", strerror(errno));
if(res >= 0)
total += res;
printf("\n Read: %d\tTotal read: %d\t Total length: %d\tfd: %d", res, total, length, fd);
if(res == 0)
{ puts("\nBREAK 0!!!!");
break;
}
if(res < 0)
{ puts("\nBREAK -1!!!");
break;
}
}
logit(ptr, "temp.log");
printf("\nRecieved:\n%s", ptr);
}
else
logit("\nEvt. malloc error -> no error handeling!", "system.log");
printf("\nSo far, so good!");
return res;
}
Just wanted to inform future developers about this bug.
The problem is, that there's a null terminator that seperates the image header and body, and when using C functions like strlen, write, puts ect, then you only get the image header... Geee took 2 weeks before I found out this problem . Solution: Simply do not use functions that terminate upon 0x00, and rely on the size you actually have read.
Regards Jnusa
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.