Exemplo n.º 1
0
def process_request():
  """
  <Purpose>
    Server thread for processing connections using select ...
  """
  while True:
    #Pass list of Inputs, Outputs for select which returns if any activity
    #occurs on any socket.
    ret = lind_test_server.select_syscall(11, inputs, outputs, excepts, 5)

    #Check for any activity in any of the Input sockets...
    for sock in ret[1]:
      #If the socket returned was listerner socket, then there's a new conn.
      #so we accept it, and put the client socket in the list of Inputs.
      if sock is serversockfd:
        newsockfd = lind_test_server.accept_syscall(sock)
        inputs.append(newsockfd[2])
      #Write to a file...
      elif sock is filefd:
        emultimer.sleep(1)
        assert lind_test_server.write_syscall(sock, 'test') == 4, \
          "Failed to write into a file..."
        lind_test_server.lseek_syscall(sock, 0, SEEK_SET)
        inputs.remove(sock)
      #If the socket is in established conn., then we recv the data, if
      #there's no data, then close the client socket.
      else:
        data = lind_test_server.recv_syscall(sock, 100, 0)
        if data:
          assert data == "test", "Recv failed in select..."
          #We make the ouput ready, so that it sends out data... 
          if sock not in outputs:
            outputs.append(sock)
        else:         
          #No data means remote socket closed, hence close the client socket
          #in server, also remove this socket from readfd's. 
          lind_test_server.close_syscall(sock)
          inputs.remove(sock)
    
    #Check for any activity in any of the output sockets...
    for sock in ret[2]:
      if sock is filefd:
        assert lind_test_server.read_syscall(sock, 4) == "test", \
          "Failed to read from a file..."
        #test for file finished, remove from monitoring.
        outputs.remove(sock)
      else:
        lind_test_server.send_syscall(sock, data, 0)
        #Data is sent out this socket, it's no longer ready for writing
        #remove this socket from writefd's. 
        outputs.remove(sock)

  lind_test_server.close_syscall(serversockfd)
Exemplo n.º 2
0
def process_request():
    """
  <Purpose>
    Server thread for processing connections using select ...
  """
    while True:
        #Pass list of Inputs, Outputs for select which returns if any activity
        #occurs on any socket.
        ret = lind_test_server.select_syscall(11, inputs, outputs, excepts, 5)

        #Check for any activity in any of the Input sockets...
        for sock in ret[1]:
            #If the socket returned was listerner socket, then there's a new conn.
            #so we accept it, and put the client socket in the list of Inputs.
            if sock is serversockfd:
                newsockfd = lind_test_server.accept_syscall(sock)
                inputs.append(newsockfd[2])
            #Write to a file...
            elif sock is filefd:
                emultimer.sleep(1)
                assert lind_test_server.write_syscall(sock, 'test') == 4, \
                  "Failed to write into a file..."
                lind_test_server.lseek_syscall(sock, 0, SEEK_SET)
                inputs.remove(sock)
            #If the socket is in established conn., then we recv the data, if
            #there's no data, then close the client socket.
            else:
                data = lind_test_server.recv_syscall(sock, 100, 0)
                if data:
                    assert data == "test", "Recv failed in select..."
                    #We make the ouput ready, so that it sends out data...
                    if sock not in outputs:
                        outputs.append(sock)
                else:
                    #No data means remote socket closed, hence close the client socket
                    #in server, also remove this socket from readfd's.
                    lind_test_server.close_syscall(sock)
                    inputs.remove(sock)

        #Check for any activity in any of the output sockets...
        for sock in ret[2]:
            if sock is filefd:
                assert lind_test_server.read_syscall(sock, 4) == "test", \
                  "Failed to read from a file..."
                #test for file finished, remove from monitoring.
                outputs.remove(sock)
            else:
                lind_test_server.send_syscall(sock, data, 0)
                #Data is sent out this socket, it's no longer ready for writing
                #remove this socket from writefd's.
                outputs.remove(sock)

    lind_test_server.close_syscall(serversockfd)
Exemplo n.º 3
0
def do_server():
    newsocketfd = lind_test_server.accept_syscall(serversockfd)
    fd = newsocketfd[2]
    lind_test_server.send_syscall(fd, 'jhasdfhjsa', 0)
    lind_test_server.setshutdown_syscall(fd, SHUT_RDWR)

    try:
        # should fail!!!
        lind_test_server.send_syscall(fd, 'jhasdfhjsa', 0)
    except:
        pass
    else:
        print "send after shutdown didn't fail!!!"
Exemplo n.º 4
0
def do_server():
    newsocketfd = lind_test_server.accept_syscall(serversockfd)
    fd = newsocketfd[2]
    lind_test_server.send_syscall(fd, 'jhasdfhjsa', 0)
    lind_test_server.setshutdown_syscall(fd, SHUT_RDWR)

    try:
        # should fail!!!
        lind_test_server.send_syscall(fd, 'jhasdfhjsa', 0)
    except:
        pass
    else:
        print "send after shutdown didn't fail!!!"
def process_request():
    """
  <Purpose>
    Process the incoming data using above specifed tests
  """

    rip, rport, newsockfd = lind_test_server.accept_syscall(serversockfd)

    #Process first test...
    try:
        msg = lind_test_server.recvfrom_syscall(newsockfd, 100, MSG_PEEK)
        assert len(msg[2]) == 100, "Length expected 100 bytes to peek, but only" \
          + " got " + str(len(msg[2])) + " bytes."
        msg = lind_test_server.recvfrom_syscall(newsockfd, 100, 0)
        assert len(msg[2]) == 100, "Length expected 100 bytes to read, but only" \
          + " got " + str(len(msg[2])) + " bytes."
    except Exception, e:
        print 'TEST:- W:100, P:100, R:100 : ', e
def process_request():
  """
  <Purpose>
    Process the incoming data using above specifed tests
  """

  rip, rport, newsockfd = lind_test_server.accept_syscall(serversockfd)  
  
  #Process first test...
  try:
    msg = lind_test_server.recvfrom_syscall(newsockfd, 100, MSG_PEEK)
    assert len(msg[2]) == 100, "Length expected 100 bytes to peek, but only" \
      + " got " + str(len(msg[2])) + " bytes."
    msg = lind_test_server.recvfrom_syscall(newsockfd, 100, 0)
    assert len(msg[2]) == 100, "Length expected 100 bytes to read, but only" \
      + " got " + str(len(msg[2])) + " bytes."
  except Exception, e:
    print 'TEST:- W:100, P:100, R:100 : ', e
Exemplo n.º 7
0
def do_server():
  
  newsocketfd = lind_test_server.accept_syscall(serversockfd)
        print 'Test:- W:100, Peek several times : ', e

    emultimer.sleep(0.2)

    #Process fourth test...
    try:
        msg = lind_test_server.recvfrom_syscall(newsockfd, 100, MSG_PEEK)
        assert len(msg[2]) == 50, "Length expected 50 bytes to peek, but only" \
          + " got " + str(len(msg[2])) + " bytes."
    except Exception, e:
        print 'Test:- W:100 P:50 : ', e

    #Gracefully close the socket
    lind_test_server.close_syscall(newsockfd)

    rip, rport, newsockfd = lind_test_server.accept_syscall(serversockfd)

    #Process first test...
    try:
        msg = lind_test_server.recvfrom_syscall(newsockfd, 100, MSG_PEEK)
        assert len(msg[2]) == 100, "Length expected 100 bytes to peek, but only" \
          + " got " + str(len(msg[2])) + " bytes."
        msg = lind_test_server.recvfrom_syscall(newsockfd, 100, 0)
        assert len(msg[2]) == 100, "Length expected 100 bytes to read, but only" \
          + " got " + str(len(msg[2])) + " bytes."
    except Exception, e:
        print 'TEST:- W:100, P:100, R:100 : ', e

    emultimer.sleep(0.2)

    #Process second test...
Exemplo n.º 9
0
def process_request():
  """
  <Purpose>
    Server thread for processing connections using poll ...
  """
  while True:
    #Pass list of sockets that needs for polling which returns if any activity
    #occurs on any socket.
    poll_vals = lind_test_server.poll_syscall(polled, 5)
    ret = [poll_vals[0],[],[],[]]
      
    ret[1] = [x['fd'] for x in poll_vals[1] if x['revents'] & lind_test_server.POLLIN]
    ret[2] = [x['fd'] for x in poll_vals[1] if x['revents'] & lind_test_server.POLLOUT]

    #Check for any activity in any of the Input sockets...
    for sock in ret[1]:
      
      #If the socket returned was listerner socket, then there's a new conn.
      #so we accept it, and put the client socket in the list of Inputs.
      if sock is serversockfd:
        newsockfd = lind_test_server.accept_syscall(sock)
        new_poll =  {'fd':newsockfd[2], 'events':lind_test_server.POLLIN, 'revents':0}
        polled.append(new_poll)
      #Write to a file...
      elif sock is filefd:
        assert lind_test_server.write_syscall(sock, 'test') == 4, \
          "Failed to write into a file..."
        lind_test_server.lseek_syscall(sock, 0, SEEK_SET)
        #Once the write is successful into a file, Modify the file descriptor
        #so that its ready for reading out of the file.
        [x for x in polled if x['fd'] == sock][0]['events'] = \
          lind_test_server.POLLOUT
      #If the socket is in established conn., then we recv the data, if
      #there's no data, then close the client socket.
      else:
        data = lind_test_server.recv_syscall(sock, 100, 0)
        if data:
          assert data == "test", "Recv failed in select..."
          #This socket is ready for writing, modify the socket descriptor
          #to be in read-write mode. This socket can write data out to network 
          [x for x in polled if x['fd'] == sock][0]['events'] = \
            lind_test_server.POLLIN | lind_test_server.POLLOUT
        else:
          #No data means remote socket closed, hence close the client socket
          #in server, also remove this socket from polling.    
          lind_test_server.close_syscall(sock)
          to_go = [x for x in polled if x['fd'] == sock]
          map(polled.remove, to_go)
    
    #Check for any activity in any of the output sockets...
    for sock in ret[2]:
      if sock is filefd:
        assert lind_test_server.read_syscall(sock, 4) == "test", \
          "Failed to read from a file..."
        #test for file finished, remove from polling.
        to_go = [x for x in polled if x['fd'] == sock]
        map(polled.remove, to_go)
      else:
        lind_test_server.send_syscall(sock, data, 0)
        #Data is sent out of this socket, it's no longer ready for writing,
        #modify it only read mode.
        [x for x in polled if x['fd'] == sock][0]['events'] = \
          lind_test_server.POLLIN

  lind_test_server.close_syscall(serversockfd)
Exemplo n.º 10
0
  emultimer.sleep(0.2)

  #Process fourth test...
  try:
    msg = lind_test_server.recvfrom_syscall(newsockfd, 100, MSG_PEEK)
    assert len(msg[2]) == 50, "Length expected 50 bytes to peek, but only" \
      + " got " + str(len(msg[2])) + " bytes."
  except Exception, e:
    print 'Test:- W:100 P:50 : ', e
  
  #Gracefully close the socket
  lind_test_server.close_syscall(newsockfd)


  rip, rport, newsockfd = lind_test_server.accept_syscall(serversockfd)  
  
  #Process first test...
  try:
    msg = lind_test_server.recvfrom_syscall(newsockfd, 100, MSG_PEEK)
    assert len(msg[2]) == 100, "Length expected 100 bytes to peek, but only" \
      + " got " + str(len(msg[2])) + " bytes."
    msg = lind_test_server.recvfrom_syscall(newsockfd, 100, 0)
    assert len(msg[2]) == 100, "Length expected 100 bytes to read, but only" \
      + " got " + str(len(msg[2])) + " bytes."
  except Exception, e:
    print 'TEST:- W:100, P:100, R:100 : ', e

  emultimer.sleep(0.2)

  #Process second test...