The UNIX and Linux Forums  


Go Back   The UNIX and Linux Forums > Top Forums > High Level Programming
.
google unix.com



High Level Programming Post questions about C, C++, Java, SQL, and other programming languages here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
read and write from a file rinku Shell Programming and Scripting 2 01-11-2008 01:22 AM
read/write socket error gio High Level Programming 2 04-17-2007 12:52 AM
sed to read and write to very same file 435 Gavea Shell Programming and Scripting 5 06-30-2006 12:04 AM
popening for read and write szzz High Level Programming 1 11-18-2003 12:05 PM
read, write & STDOUT_FILENO.... M3xican High Level Programming 2 07-17-2002 05:41 PM

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Bulgarian Greek Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 08-30-2006
EltonSky EltonSky is offline
Registered User
  
 

Join Date: Aug 2006
Posts: 11
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
  #2 (permalink)  
Old 08-30-2006
Hitori's Avatar
Hitori Hitori is offline Forum Advisor  
Registered User
  
 

Join Date: Jun 2006
Posts: 360
If you are using sockets send() and recv() offer much greater control over your data transmission
  #3 (permalink)  
Old 08-30-2006
Corona688 Corona688 is offline
Registered User
  
 

Join Date: Aug 2005
Location: Saskatchewan
Posts: 1,969
Quote:
Originally Posted by Hitori
If you are using sockets send() and recv() offer much greater control over your data transmission
But ordinary read and write should still work, yes? No reason for them to segfault without an error in the program. If my hunch is correct send() and recv() could suffer the same issues...

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.
  #4 (permalink)  
Old 08-30-2006
Hitori's Avatar
Hitori Hitori is offline Forum Advisor  
Registered User
  
 

Join Date: Jun 2006
Posts: 360
Try them and if the error disappears then the reason exists
  #5 (permalink)  
Old 08-30-2006
Corona688 Corona688 is offline
Registered User
  
 

Join Date: Aug 2005
Location: Saskatchewan
Posts: 1,969
How so? Even if the error goes away, the program still lacks the error-checking to handle them. It should fail, not crash.
  #6 (permalink)  
Old 08-30-2006
EltonSky EltonSky is offline
Registered User
  
 

Join Date: Aug 2006
Posts: 11
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
Closed Thread

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT -4. The time now is 08:14 AM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0