Example #1
0
import lind_test_server

from lind_net_constants import *

SyscallError = lind_test_server.SyscallError

sockfd = lind_test_server.socket_syscall(AF_INET, SOCK_STREAM, 0)

# should work...
lind_test_server.bind_syscall(sockfd, '127.0.0.1', 50102)

# let's set some options!!!    I'll check for function in different tests...
assert (lind_test_server.getsockopt_syscall(sockfd, SOL_SOCKET,
                                            SO_REUSEPORT) == 0)
assert (lind_test_server.getsockopt_syscall(sockfd, SOL_SOCKET,
                                            SO_LINGER) == 0)
assert (lind_test_server.getsockopt_syscall(sockfd, SOL_SOCKET,
                                            SO_KEEPALIVE) == 0)

# reuseport
assert (lind_test_server.getsockopt_syscall(sockfd, SOL_SOCKET,
                                            SO_REUSEPORT) == 0)
lind_test_server.setsockopt_syscall(sockfd, SOL_SOCKET, SO_REUSEPORT, 1)
assert (lind_test_server.getsockopt_syscall(sockfd, SOL_SOCKET,
                                            SO_REUSEPORT) == 1)

assert (lind_test_server.getsockopt_syscall(sockfd, SOL_SOCKET,
                                            SO_LINGER) == 0)
assert (lind_test_server.getsockopt_syscall(sockfd, SOL_SOCKET,
                                            SO_KEEPALIVE) == 0)
assert (lind_test_server.getsockopt_syscall(sockfd, SOL_SOCKET,
import lind_test_server


from lind_net_constants import *

SyscallError = lind_test_server.SyscallError


sockfd = lind_test_server.socket_syscall(AF_INET, SOCK_STREAM, 0)

# should work...
lind_test_server.bind_syscall(sockfd,'127.0.0.1',50102)



# let's set some options!!!    I'll check for function in different tests...
assert(lind_test_server.getsockopt_syscall(sockfd, SOL_SOCKET, SO_REUSEPORT)==0)
assert(lind_test_server.getsockopt_syscall(sockfd, SOL_SOCKET, SO_LINGER)==0)
assert(lind_test_server.getsockopt_syscall(sockfd, SOL_SOCKET, SO_KEEPALIVE)==0)


# reuseport
assert(lind_test_server.getsockopt_syscall(sockfd, SOL_SOCKET, SO_REUSEPORT)==0)
lind_test_server.setsockopt_syscall(sockfd, SOL_SOCKET, SO_REUSEPORT, 1)
assert(lind_test_server.getsockopt_syscall(sockfd, SOL_SOCKET, SO_REUSEPORT)==1)

assert(lind_test_server.getsockopt_syscall(sockfd, SOL_SOCKET, SO_LINGER)==0)
assert(lind_test_server.getsockopt_syscall(sockfd, SOL_SOCKET, SO_KEEPALIVE)==0)
assert(lind_test_server.getsockopt_syscall(sockfd, SOL_SOCKET, SO_REUSEPORT)==1)

Example #3
0
"""
File : ut_lind_net_udp.py

Unit test for UDP in connection mode, i.e using connect_syscall() to connect
to peer and sending a msg using send_syscall() instead of sendto_sycall(). 
"""
import lind_test_server
import emultimer

from lind_net_constants import *

SyscallError = lind_test_server.SyscallError

#Both client and server are run from this file, hence opening sockets for both
listensockfd = lind_test_server.socket_syscall(AF_INET, SOCK_DGRAM, 0)
sendsockfd = lind_test_server.socket_syscall(AF_INET, SOCK_DGRAM, 0)

#Bind the socket to an address, this is important in repy, because the recvfrom
#_syscall() doesn't work properly without binding the address first.
lind_test_server.bind_syscall(listensockfd, '127.0.0.1', 50300)


def process_request():
    msg = None
    # Read the data in the socket.
    try:
        msg = lind_test_server.recvfrom_syscall(listensockfd, 1024, 0)
        assert msg != None, "Socket failed to recv message."
    except Exception, e:
        print "UDP Connect Test : ", e
"""
File : ut_lind_net_udp.py

Unit test for UDP in connection mode, i.e using connect_syscall() to connect
to peer and sending a msg using send_syscall() instead of sendto_sycall(). 
"""
import lind_test_server
import emultimer

from lind_net_constants import *

SyscallError = lind_test_server.SyscallError

#Both client and server are run from this file, hence opening sockets for both
listensockfd = lind_test_server.socket_syscall(AF_INET, SOCK_DGRAM, 0)
sendsockfd = lind_test_server.socket_syscall(AF_INET, SOCK_DGRAM, 0)

#Bind the socket to an address, this is important in repy, because the recvfrom
#_syscall() doesn't work properly without binding the address first.
lind_test_server.bind_syscall(listensockfd, '127.0.0.1', 50300)

def process_request():
  msg = None
  # Read the data in the socket.
  try:
    msg = lind_test_server.recvfrom_syscall(listensockfd, 1024, 0)
    assert msg != None, "Socket failed to recv message."
  except Exception, e:
    print "UDP Connect Test : ", e

#Run the listen socket in seperate thread, since send/listen should be started
import lind_test_server



from lind_net_constants import *

SyscallError = lind_test_server.SyscallError

sockfd = lind_test_server.socket_syscall(AF_INET, SOCK_STREAM, 0)
sockfd2 = lind_test_server.socket_syscall(AF_INET, SOCK_STREAM, IPPROTO_TCP)

sockfd3 = lind_test_server.socket_syscall(AF_INET, SOCK_DGRAM, 0)
sockfd4 = lind_test_server.socket_syscall(AF_INET, SOCK_DGRAM, IPPROTO_UDP)


try:
  # let's try to use an incorrect setting
  lind_test_server.socket_syscall(AF_UNIX, SOCK_DGRAM, 0)

except:
  pass
else:
  print "Should be an error"

sockfd = lind_test_server.socket_syscall(AF_INET, SOCK_STREAM, 0)

lind_test_server.close_syscall(sockfd)