[pso] test tema5 linux
Sava Ionut
pso@cursuri.cs.pub.ro
Fri, 11 Jun 2004 04:12:25 -0700 (PDT)
Dupa parerea mea se mai poate intampla o
nesincronizare la testul temei nr 5 pe linux. Si anume
se fac multe grupuri de instr:
ins/out out/ins
------------------------------------------------
wait_conn make_conn
care s-ar reduce la urm operatii :
do_listen(type, port) recv_port
add_rule... (optional) connect
send_port
accept
Paradoxal mie mi se intampla cateodata sa faca
send_port si sa se transmita pechetele inainte ca sa
ajunga sa se faca recv_port si mi se blocheaza.
As propune o solutie de compromis (sleep(1) inainte de
send port):
void wait_conn(int type, int pass, int add_rule)
{
unsigned int sock, sock2, port;
do {
port=1024+(rand()%64000);
printf("PORT = %d\n",port);
} while ((sock=do_listen(type, port)) < 0);
if (add_rule) {
char add_rule[1024];
snprintf(add_rule, 1023, "./ipnecklace add 0.0.0.0/0
0.0.0.0/0 0:65535 %d:%d", port, port);
printf("COMMAND = %s\n",add_rule);
test("add firewall rule", system(add_rule) == 0);
test_rules(1);
}
sleep(1); <<<=====AICI==========
test("send port", do_send(control_socket, port) ==
0);
if (type == SOCK_STREAM)
test("wait connection", (sock2=do_accept(sock))*pass
> 0);
if (pass > 0) {
if (type == SOCK_STREAM) {
pong_ping(sock2);
close(sock2);
} else {
struct sockaddr_in addr;
int tmp, tmp2=sizeof(addr);
test("UDP pong", recvfrom(sock, &tmp, 4, 0, (struct
sockaddr*)&addr, &tmp2) == 4 && tmp == seq++);
test("UDP ping", (tmp=seq++,sendto(sock, &tmp, 4,
sizeof(tmp), (struct sockaddr*)&addr, sizeof(addr)) ==
4));
}
}
close(sock);
}
As vrea sa stiu daca ce zic eu este corect, sau daca
gresesc cam care ar fi greseala.
__________________________________
Do you Yahoo!?
Friends. Fun. Try the all-new Yahoo! Messenger.
http://messenger.yahoo.com/