Visit Jeremy's Blog.
Go Back > Forums > Non-*NIX Forums > Programming
User Name
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.


  Search this Thread
Old 08-22-2004, 01:17 PM   #1
Registered: Jan 2004
Posts: 105

Rep: Reputation: 15
difficulties with large files and system call read/write

The scenrio is as follows:

I doing a impact tests for a network application. Its being done on a local network. Transfer of information involve opening a tcp socket then closing upon transfer, like an http request (1MB transfer chunks). The performance test is a disk impact tests, writing a large file 4-8Gigs and taking a median of three or four of these tests times. The writes occur continously, no pause between file writes in the tests. Then the network application is run during this tests to observe what impact it has on the test's time.

The problem is the test running with the application causes the socket read to seem to hang on the application receving the data (this is the side the disk impact test is running on). Thus when the performance tests starts read(socket, xbuffer ,count) hangs indefinately, even when the performance test completes. It never returns an error, or indicate an unsucessful read, it just hangs.

I know the socket connection is still good, I can verfiy that from both side. I also verfied that the sender side indicates that the actual socket would block so it doesn;t send data. Why would it actually indicate the socket is busy even though nothing has been sent to it?

The tests are running on Fedora Core 2 machines.
Any ideas??

Last edited by jwstric2; 08-22-2004 at 01:24 PM.
Old 08-22-2004, 03:21 PM   #2
Registered: Jan 2004
Posts: 105

Original Poster
Rep: Reputation: 15
I found out where my code is failing, buts its a strange fail..

The server uses the following code. The request for the data is a udp packet which will be able to reselect another machine in the long run but for now it simply assumes the machine is up.

void putMorsel(int myNode, struct data_request *request){
  struct scavenger_morsel_msg msg;
  struct data_request_holder *data_request_holder;
  int server_sockfd;
  int bind_port;
  int retval;
  fd_set tmp_rfds;
  int tcp_buffer_size = TCP_BUFFER_SIZE;
  struct timeval accept_timeout = {0, 0};

   * socket: create the parent socket 
  server_sockfd = socket(AF_INET, SOCK_STREAM, 0);
  if (server_sockfd < 0)

  bind_port = bindServerSocket(server_sockfd);
  if(bind_port < 0){
  msg.hdr.orig = myNode;
  msg.hdr.flags = 0;
  msg.flags = 0;
  msg.morsel_id = request->morsel_id;
  msg.port = bind_port;   

  FD_SET(server_sockfd, &tmp_rfds);  
  listen(server_sockfd, 1);  


  pSend(request->benefactorNode, MSG_SCAVENGER_PUT, 0, 1, sizeof(msg), &msg);
  accept_timeout.tv_sec = TIMEOUT;
  retval = select_non_interruptible(NUM_PORTS, &tmp_rfds, NULL, NULL, &accept_timeout);

  if(retval == 0){
    goto send;
  else if (retval > 0){
    data_request_holder = (struct data_request_holder *)malloc(sizeof(struct data_request_holder));
      goto cleanup;
    data_request_holder->client_sockfd = accept(server_sockfd, NULL, 0);    
    setsockopt(data_request_holder->client_sockfd, SOL_SOCKET, SO_SNDBUF, &tcp_buffer_size, sizeof(tcp_buffer_size));
    if(data_request_holder->client_sockfd < 0){
      goto cleanup;
    data_request_holder->curr_transfer_size = 0;
    data_request_holder->request_data = request;
    data_request_holder->request_type = PUT_REQUEST;

    if(!l_insert(request_list, data_request_holder)){
      goto cleanup;
    FD_SET(data_request_holder->client_sockfd, &wfds);

  FD_CLR(server_sockfd, &tmp_rfds);

Somwtimes the line: retval = select_non_interruptible(NUM_PORTS, &tmp_rfds, NULL, NULL, &accept_timeout); returns 0 even though it appears the client actually connected to the server. So the client connected somehow but the server can;t distinguish this. (the accept was never called)

Last edited by jwstric2; 08-22-2004 at 03:23 PM.
Old 08-22-2004, 11:42 PM   #3
LQ Newbie
Registered: Apr 2004
Location: India
Distribution: RedHat
Posts: 29

Rep: Reputation: 15
use non_blocking option with sockfd

I think, it may be happening that ur socket is being blocked when the data is not available. so try the option of setting the socketfd with non-blocking option
fcntl(sockfd,NON_BLOCK,,...)..something like this..


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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 Off
HTML code is Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
write system call basics.... bisDude Programming 6 11-04-2005 06:48 PM
How to write a system call to display the process information? Programming 3 09-30-2005 01:05 AM
Problem using 'read' system call buckles Programming 6 05-10-2005 11:45 AM
Problem w/ 'read' system call - RH 7.3 buckles Linux - Newbie 3 05-07-2005 12:03 AM
Change from Read only to Read Write File System? justiceisblind Linux - Newbie 3 03-03-2002 07:23 PM > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 10:17 AM.

Main Menu
Write for LQ is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration