Results 1 to 10 of 11
Hi,
I wonder if anybody has come across this before, I'm trying to create a large buffer in my program so that I can send, and then receive on another ...
- 02-09-2011 #1Just Joined!
- Join Date
- Feb 2011
- Posts
- 10
problem creating a large buffer
Hi,
I wonder if anybody has come across this before, I'm trying to create a large buffer in my program so that I can send, and then receive on another pc, more than 4096 bytes (this seems to be the default for the serial port). I thought this might work:
and then read at the receiving programCode:#define BUFSIZE 10000 char buffer[BUFSIZE]; write(fd, message, BUFSIZE);
Unfortunately it's still getting truncated at 4096 bytes. Maybe there's an easier way of doing this? Any ideas on this would be appreciatedCode:#define BUFSIZE 10000 char data[BUFSIZE]; read(fd, data, BUFSIZE);
Thanks
- 02-09-2011 #2Just Joined!
- Join Date
- Feb 2011
- Posts
- 12
You can do,
And,Code:#define BUFFSIZE 4096 int sent = 0; while (sent <= sizeof(message) - BUFFSIZE) { sent += write(fd, message + sent, BUFFSIZE); } write(fd, message + sent, sizeof(message) - sent);
That is, send the message in chunks of 4096 bytes, and receive the data in chunks of 4096, until the shorter tail completes the transition.Code:#define BUFFSIZE 4096 int received = 0; while (read(fd, data + received, BUFFSIZE) == BUFFSIZE) { received += BUFFSIZE; }
Note: If you send data structures, you should look into serialisation.
- 02-09-2011 #3Just Joined!
- Join Date
- Feb 2011
- Posts
- 10
Hi,
Thanks for the suggestion, but unfortunately I can't do it this way, due to the way the data will be transmitted (it's a simulation of an instrument). It won't wait for the receiving program to process the first 4096 bytes and then send more. It will just send it continuosly. So the receiving program must be able to deal with the full data message, which is approx 7800 bytes.
- 02-09-2011 #4Just Joined!
- Join Date
- Feb 2011
- Posts
- 12
You can use threads, but it's not too simple. What type of transmission are you using?
- 02-09-2011 #5Just Joined!
- Join Date
- Feb 2011
- Posts
- 10
Sorry, im not sure exactly what you mean by 'type of transmission'?
- 02-09-2011 #6Just Joined!
- Join Date
- Feb 2011
- Posts
- 12
Are you using TCP Sockets, or something else?
- 02-09-2011 #7Just Joined!
- Join Date
- Feb 2011
- Posts
- 10
i dont know, i don't really have an in depth knowledge of how that works. I didnt mess around with it, so it's most likely whatever the default settings are. All I can tell you is it's Fedora 14 if that helps.
Sorry, im fairly new at linux
- 02-09-2011 #8Just Joined!
- Join Date
- Feb 2011
- Posts
- 12
I'm trying to understand what type of transmission you are using, so I can determine why it limits you to 4096 bytes.
How do you get the file descriptor to write to or to read from? Do you set Internet Sockets or UNIX Domain Sockets, or call open(2) on a file or a device?
- 02-09-2011 #9Just Joined!
- Join Date
- Feb 2011
- Posts
- 10
i call open on the device:
strcpy(device,"/dev/ttyS1");
fd = open( device, O_RDWR | O_NOCTTY | O_NONBLOCK );
- 02-09-2011 #10Just Joined!
- Join Date
- Feb 2011
- Posts
- 12
The write(2) function has a limit, depending on the implementation; however, it does sound unlikely that this limit is 4096 bytes.
Anyway, I'm out of ideas.


Reply With Quote