Find the answer to your Linux question:
Page 1 of 2 1 2 LastLast
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 ...
  1. #1
    Just 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:

    Code:
    #define BUFSIZE 10000
    
    char buffer[BUFSIZE]; 
    write(fd, message, BUFSIZE);
    and then read at the receiving program

    Code:
    #define BUFSIZE 10000
    
    char data[BUFSIZE]; 
    read(fd, data, 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 appreciated

    Thanks

  2. #2
    Just Joined!
    Join Date
    Feb 2011
    Posts
    12
    You can do,

    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);
    And,

    Code:
    #define BUFFSIZE 4096
    int received = 0;
    while (read(fd, data + received, BUFFSIZE) == BUFFSIZE) {
            received += BUFFSIZE;
    }
    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.

    Note: If you send data structures, you should look into serialisation.

  3. #3
    Just 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.

  4. #4
    Just Joined!
    Join Date
    Feb 2011
    Posts
    12
    You can use threads, but it's not too simple. What type of transmission are you using?

  5. #5
    Just Joined!
    Join Date
    Feb 2011
    Posts
    10
    Sorry, im not sure exactly what you mean by 'type of transmission'?

  6. #6
    Just Joined!
    Join Date
    Feb 2011
    Posts
    12
    Are you using TCP Sockets, or something else?

  7. #7
    Just 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

  8. #8
    Just 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?

  9. #9
    Just 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 );

  10. #10
    Just 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.

Page 1 of 2 1 2 LastLast

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
...