Re: recvfrom



On Sun, 12 Nov 2006 20:06:21 +0100, ¬a\/b wrote:
On 12 Nov 2006 11:09:08 GMT, Betov wrote:

"¬a\\/b" <al@xxx> écrivait news:25vdl2h4382ee2vvsrknp7sp2lqi1gk0r4@xxxxxxx:

but there is someone that can understand?

Yes: You only.

;)

it was an exercise: a try for build a routine like that (dgsendrecv())
in the book "unix sviluppo del software di networking" by Richard W.
Stevens § 8.4
the result is not very similar to the book function...

%define _P printf

.data
_Timeout_$$$_$n
db "Timeout ... " , 10 , 0

_dg$cli$_errore_di_dg$SndRcv$n
db "dg_cli: errore di dg_SndRcv" , 10 , 0

_Aggiorna_estimatori$_$delta$$u$n
db "Aggiorna estimatori, @delta=%u" , 10 , 0


.text

; ritorna -1 D[s+116Funzione_chiamante]==D[s+20qui]==-1 se errore
; ritorna 0 D[s+116Funzione_chiamante]==linea_ricevuta_len se OK
; 0r, 4r, 8c, 12b, 16ra, 20P_a
dg_threadf:
push ebx
push ecx
push edx
push edx
mov eax, [esp+20]
mov ebx, [eax]
mov edx, [eax+4]
mov ecx, [eax+8]
push 0
push 0
push 0
push ecx
push edx
push ebx
call recvfrom
mov ebx, [esp+20]
cmp eax, SOCKET_ERROR
jne .1
mov eax, -1
mov dword[ebx+16], eax
jmp short .2
..1:
mov dword[ebx+16], eax
mov eax, 0
..2:
pop edx
pop edx
pop ecx
pop ebx
ret 4

;/ V:6 508 6683040 |
;/ V:-2124692760 508 6683040 |

; int dg_SndRcv( char* ibuf, int ilen, char* obuf, int olen,
; int fd, struct sockaddr* destAdd, int destLen, int* Pint3A)
; funzione che manda domanda(obuf), riceve risposta(ibuf) usando UDP
; se timeout senza risposta o errori ritorna -1 e CF==1
; altrimenti ritorna lunghezza messaggio ricevuto e CF==0
;
; "Pint3A" punta a un vettore di 3 interi inizializzato
; per la prima volta a "Pint3A[0]=0; Pint3A[1]=0; Pint3A[2]=4;"
;
; 256+28=284, 256+32=288
; 0k, 4j, 8i, 12r, 16c, 20b, 24ra, 28P_ibuf, 32P_ilen, 36P_obuf,
; 40P_olen
; 44P_fd, 48P_destAdd, 52P_destLen, 56P_Pint3A
dg_SndRcv:
push ebx
push ecx
push edx
push esi
push edi
push ebp
sub esp, 256
%define @ibuf [esp+284]
%define @ilen [esp+288]
%define @obuf [esp+292]
%define @olen [esp+296]
%define @fd [esp+300]
%define @destAdd [esp+304]
%define @destLen [esp+308]
%define @Pint3A [esp+312]
%define @t [ebp]
%define @c [ebp+4]
%define @delta [ebp+8]
mov esi, @obuf ; 1+tre ritrasmissioni
mov ebp, @Pint3A
mov dword[esp+24], 4
mov dword[esp+16], 0
cmp dword @ibuf, 0
je .e
cmp esi, 0
je .e
cmp dword @destAdd, 0
jne .a
cmp dword @destLen, 0
jne .e
jmp short .b
..a:
cmp dword @destLen, 0
jl .e
..b:
mov ebx, @fd
cmp ebx, -1
je .e
cmp dword @ilen, 0
jle .e
cmp dword @olen, 0
jl .e
cmp ebp, 0
je .e
mov edi, @t
mov dword[esp+32], edi
jmp short .1
..e: ; here i have not ceck every possible case of errors
; in arguments
mov eax, -1
stc
jmp .f
..1: ;/ D*s="I=%d"; D[s+4]="; "; a=s; _P<(a, j);

cmp dword @t, 0
je .2
cmp dword @t, 10000
ja .c ; 10s se esageratamente grande vai e ricalcola
mov ecx, @c ; aggiorna il timer per velocita'
cmp ecx, @delta
jne .2
..c: ; maggiori ogni "delta" pacchetti
mov dword @t, 0
mov dword @c, 0
mov edi, 0
mov dword[esp+32], edi ; aggiorna estimatori ogni 200 volte
;/ a=@delta; _P<("Aggiorna estimatori, @delta=%u\n", a);
cmp dword @delta, 200
ja .2 ; delta cresce all'inizio
shl dword @delta, 1
..2:
mov dword[esp], "."
mov eax, esp
push eax
call _P
add esp, 4
mov eax, @olen
mov edx, @destAdd
mov ecx, @destLen
mov esi, @obuf
push ecx
push edx
push 0
push eax
push esi
push ebx
call sendto
cmp eax, @olen
jne .e
cmp dword[esp+16], 0
jne .3
mov ecx, @ilen
mov edx, @ibuf
lea eax, [esp+100]
mov [eax], ebx
mov dword[eax+4], edx
mov dword[eax+8], ecx
lea esi, [eax+12]
push esi
push 0
push eax
push dg_threadf
push 0
push 0
call CreateThread
cmp eax, 0
je .e
mov [esp+16], eax
..3:
mov edi, @t
..4:
mov eax, @t
push eax
call Sleep
mov eax, [esp+16]
mov ecx, esp
push ecx
push eax
call GetExitCodeThread
cmp eax, 0
je .e1
cmp dword[esp], STILL_ACTIVE
je .9
mov ebx, [esp+116]
cmp ebx, 0
jl .7
mov eax, [esp+32]
mov @t, eax
inc dword @c
;/ j=[s+32];
;/ D*s="D=%d";D[s+4]="; ";a=s;_P<(a,j);
mov eax, ebx
clc
jmp short .f
..ee:
push _Timeout_$$$_$n
call _P
add esp, 4
..e1:
mov edi, [esp+16]
push edi
call CloseHandle
cmp eax, 0
jne .7
push 0
push edi
call TerminateThread
push edi
call CloseHandle
..7: ; reset
mov dword @t, 0
mov dword @c, 0
mov dword @delta, 4
mov eax, -1
stc
jmp short .f
..9: ; il tempo aumenta se problemi
mov eax, @t
add edi, @t
inc eax
add dword[esp+32], eax
mov @t, eax
cmp edi, 30100
jbe .4 ; 30 secondi timeout per nuovo sendto
dec dword[esp+24]
jz .ee ; 1+3 volte rinvia sendto;
jmp .2
..f: ; se dopo 4 volte ancora nessuna risposta esce

%undef @t
%undef @c
%undef @delta ; e ritorna -1
%undef @fd
%undef @destAdd
%undef @destLen
%undef @Pint3A
%undef @ibuf
%undef @ilen
%undef @obuf
%undef @olen
lea esp, [esp+256]
pop ebp
pop edi
pop esi
pop edx
pop ecx
pop ebx
ret 32


/* ritorna -1 D[s+116Funzione_chiamante]==D[s+20qui]==-1 se errore
/* ritorna 0 D[s+116Funzione_chiamante]==linea_ricevuta_len se OK
/* 0r, 4r, 8c, 12b, 16ra, 20P_a
dg_threadf:
< b, c, r, r
a=[s+20]; b=*a; r=[a+4]; c=[a+8];
recvfrom(b, r, c, 0, 0, 0);
b=[s+20];
a==SOCKET_ERROR!#.1| a=-1; D[b+16]=a; #.2;
..1: D[b+16]=a; a=0;
..2:
b, c, r, r
ret 4

// V:6 508 6683040 |
// V:-2124692760 508 6683040 |

/* int dg_SndRcv( char* ibuf, int ilen, char* obuf, int olen,
/* int fd, struct sockaddr* destAdd, int destLen, int* Pint3A)
/* funzione che manda domanda(obuf), riceve risposta(ibuf) usando UDP
/* se timeout senza risposta o errori ritorna -1 e CF==1
/* altrimenti ritorna lunghezza messaggio ricevuto e CF==0
/*
/* "Pint3A" punta a un vettore di 3 interi inizializzato
/* per la prima volta a "Pint3A[0]=0; Pint3A[1]=0; Pint3A[2]=4;"
/*
/* 256+28=284, 256+32=288
/* 0k, 4j, 8i, 12r, 16c, 20b, 24ra, 28P_ibuf, 32P_ilen, 36P_obuf,
40P_olen
/* 44P_fd, 48P_destAdd, 52P_destLen, 56P_Pint3A
dg_SndRcv:
< b, c, r, i, j, k
s-=256
<< @ibuf=[s+284], @ilen=[s+288], @obuf=[s+292], @olen=[s+296]
<< @fd=[s+300], @destAdd=[s+304], @destLen=[s+308], @Pint3A=[s+312]
<< @t=[k], @c=[k+4], @delta=[k+8]
i=@obuf; k=@Pint3A; D[s+24]=4; /* 1+tre ritrasmissioni
D[s+16]=0;
D @ibuf==0#.e; i==0#.e;
D @destAdd==0!#.a| D @destLen!=0#.e; #.b;
..a: D @destLen<0 ?#.e;
..b: b=@fd; b==-1#.e; D @ilen<=0?#.e; D @olen<0?#.e;
k!#.e; j=@t; D[s+32]=j; #.1;
..e: a=-1; stc; ##.f;
..1: // D*s="I=%d"; D[s+4]="; "; a=s; _P<(a, j);
D @t!=0!#.2
D @t > 10000#.c; /* 10s se esageratamente grande vai e ricalcola
c=@c; c==@delta!#.2 /* aggiorna il timer per velocita'
..c: D @t=0; D @c=0; j=0; /* maggiori ogni "delta" pacchetti
D[s+32]=j; /* aggiorna estimatori ogni 200 volte
// a=@delta; _P<("Aggiorna estimatori, @delta=%u\n", a);
D @delta>200#.2| D @delta <<= 1; /* delta cresce
all'inizio
..2: D*s="."; a=s; _P<(a);
a=@olen; r=@destAdd; c=@destLen; i=@obuf;
sendto(b, i, a, 0, r, c); a!=@olen#.e;
D[s+16]#.3;
c=@ilen; r=@ibuf; a=&[s+100];
*a=b; D[a+4]=r; D[a+8]=c; i=&[a+12];
CreateThread(0, 0, dg_threadf, a, 0, i);
a==0#.e; [s+16]=a;
..3: j=@t;
..4: a=@t; Sleep(a);
a=[s+16]; c=s; GetExitCodeThread(a, c); a==0#.e1;
D*s!=STILL_ACTIVE!#.9
b=[s+116]; b<0?#.7;
a=[s+32]; @t=a; ++D @c;
// j=[s+32];
// D*s="D=%d";D[s+4]="; ";a=s;_P<(a,j);
a=b; clc; #.f;
..ee: _P<("Timeout ... \n");
..e1: j=[s+16]; CloseHandle(j); a==0!#.7
TerminateThread(j, 0); CloseHandle(j);
..7: D @t=0; D @c=0; D @delta=4; a=-1; stc; #.f; /* reset
..9: a=@t; j+=@t; ++a; D[s+32]+=a; @t=a; /* il tempo aumenta se
problemi
j>30100!#.4 /* 30 secondi timeout per nuovo sendto
--D[s+24]!#.ee; ##.2; /* 1+3 volte rinvia sendto;
..f: /* se dopo 4 volte ancora nessuna risposta
esce
@t, @c, @delta /* e ritorna -1
@fd, @destAdd, @destLen, @Pint3A
@ibuf, @ilen, @obuf, @olen
s=&[s+256];
b, c, r, i, j, k
ret 32

.



Relevant Pages

  • ascii to st0
    ... push IDC_ARROW ... cmp eax, 0 ... mov ebp, esp ... cmp dword @Message, WM_CLOSE ...
    (alt.lang.asm)
  • Re: Interesting Web Site on Open Source Development
    ... mov D§esp 0DEADBEEF call Code04013A0 ... call Code0401100 push eax lea eax D§esp+014 push Data0402124 ... push eax call 'USER32.wsprintfA' add esp 0C push 030 lea ecx D§esp+014 push ecx ...
    (alt.lang.asm)
  • a problem in n5.dll in windows 95
    ... eax srandMl ... mov ebp, esp ... push dword @lpm ... mov esi, @adw ...
    (alt.lang.asm)
  • Re: recvfrom
    ... push ebx ... mov esi, ... lea eax, ... cmp eax, SOCKET_ERROR ...
    (alt.lang.asm)
  • Re: win32 CreateThread() question
    ... push ebx ... mov esi, ... lea eax, ... cmp eax, SOCKET_ERROR ...
    (comp.programming.threads)