![]() |
|
|
|
|
|||||||
| Forums | Portal | Register | Forum Rules | FAQ | Contribute | Members List | Arcade | Search | Today's Posts | Mark Forums Read |
| High Level Programming Post questions about C, C++, Java, SQL, and other programming languages here. |
|
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| read and write from a file | rinku | Shell Programming and Scripting | 2 | 01-10-2008 09:22 PM |
| read/write socket error | gio | High Level Programming | 2 | 04-16-2007 08:52 PM |
| sed to read and write to very same file | 435 Gavea | Shell Programming and Scripting | 5 | 06-29-2006 08:04 PM |
| popening for read and write | szzz | High Level Programming | 1 | 11-18-2003 08:05 AM |
| read, write & STDOUT_FILENO.... | M3xican | High Level Programming | 2 | 07-17-2002 01:41 PM |
|
|
Submit Tools | LinkBack | Thread Tools | Display Modes |
|
|||
|
Problem with read & write
Hello mates:
I met problem with using read() & write(). I m trying to use read twice on client first time is the size of buffer, 2nd time is the buffer. I think I have to, coz I dnot know file size. So, I write twice on server as well -- 1st, filesize; 2nd, buffer. The problem is, sometimes, I cannot get anything at 2nd time. The file I got is empty, nothing. However, if I put a sleep(1) before the 2nd write() on server, I can read( but this sometimes may cause a segmentation fault)... i.e.: Client Server read() 1st write() 1st <-----both OK (if I put a sleep(1)here, it's OK) read() 2d write() 2nd <-----problem Does anybody know the reason? BEST REGARDS, Elton |
| Forum Sponsor | ||
|
|
|
|||
|
Quote:
Check to make sure you're recieving the number of bytes you intended. I think you might be getting crazy numbers for filesize, which could cause the crash. |
|
|||
|
It's really a frustrating problem
I m trying to use 2 write() in a row, first write() is used to send file size, 2nd send the file. On client side, I use malloc() for the buf size and free later. Current situation is if I put sth (like sleep(1) or a read()) btw 2 write() , they both work fine. Othrewise, I lose some bytes on client side which is from the 2nd write(). That makes the browser cannnot recognize the HTTP header.... REGARDS, ELton |