• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: Errors occur when using NSOutputStream to transfer big files
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Errors occur when using NSOutputStream to transfer big files


  • Subject: Re: Errors occur when using NSOutputStream to transfer big files
  • From: Andrew Farmer <email@hidden>
  • Date: Tue, 28 Apr 2009 22:09:46 -0700

On 28 Apr 09, at 21:11, yiling wu wrote:
I'm trying to use the NSOutputStream class to transfer some audio file
through Bonjour service which is implemented on the iPhone simulator.I try
the following code with some small text files. It works well. But there are
always some error occurs() when I try to send the bigger ones -- some audio
file.

Let me guess: All your test files were under 1kb.

   uint8_t *readBytes = (uint8_t *)[myData bytes];
   NSUInteger  byteIndex = 0;
   int myData_len = [myData length];

while (_outStream && [_outStream hasSpaceAvailable]) {
This loop condition makes no sense.

readBytes += byteIndex;
This should probably be "readBytes = byteIndex". Or eliminate the extra variable entirely.

unsigned int len = ((myData_len - byteIndex >= 1024) ? 1024 :
(myData_len-byteIndex));
uint8_t buf[len];
(void)memcpy(buf, readBytes, len);
Come to think of it, why are you doing a memcpy at all? All of your data is already in a buffer; there's no need to put it into another buffer just to write it.


len = [_outStream write:(const uint8_t *)buf maxLength:len];
byteIndex += len;
}

_______________________________________________

Cocoa-dev mailing list (email@hidden)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden


References: 
 >Errors occur when using NSOutputStream to transfer big files (From: yiling wu <email@hidden>)

  • Prev by Date: Errors occur when using NSOutputStream to transfer big files
  • Next by Date: How to get finder type "Open With" dialog box
  • Previous by thread: Errors occur when using NSOutputStream to transfer big files
  • Next by thread: How to get finder type "Open With" dialog box
  • Index(es):
    • Date
    • Thread