|
From: Rosario on 19 Dec 2007 01:48 what do you think about unified socket and file read-write operations? [in Windows] Do you like my read-write routines for socket and files? with this i can open a 2 way stream thype and write in socket like they are 2 files one for input and anhother for output -------------------------------- the OS api definitions BOOL WriteFile( HANDLE hFile, // handle to file to write to LPCVOID lpBuffer, // pointer to data to write to file DWORD nNumberOfBytesToWrite, // number of bytes to write // pointer to number of bytes written LPDWORD lpNumberOfBytesWritten, // pointer to structure needed for overlapped I/O LPOVERLAPPED lpOverlapped ); int send ( SOCKET s, const char FAR * buf, int len, int flags ); /* Definition of the control structure for streams*/ typedef struct _iobuf {int cnt; /* caratteri rimasti */ char* ptr; /* posizione del prossimo carattere */ char* base; /* indirizzo del buffer */ unsigned flag; /* modalita' di accesso al file */ int fd; /* descrittore di file */ }FILE; // 4*5=20 enum _flags { _READ = 01, /* file aperto in lettura (unset for read *)1 */ _WRITE = 02, /* file aperto in scrittura(unset for write*)2 */ _UNBUF = 04, /* file non bufferizzato 4 */ _EOF =010, /* EOF raggiunto sul file 8 */ _ERR =020, /* rilevamento di un errore hardwar-OS *16 */ _BAD =040, /* ungetc fallisce *32 */ _DISKF =0100, /* tipo di file "disco" 64 */ /* quando finisce il contatore cnt => chiudi lo stram con EOF 128 */ _EOFN = 0200, /* qualche funzione del C++ non riesce a prendere un un input di un dato formato 256 */ _FAIL = 0400, _SOCK =01000 /* Serve per flush in lettura */ }; ; int ReadFile_r(FILE* fp, char* bu, ; uns len, uns* ncLetti, void* ovl) ; considero ovl se fp � un socket => come argomento falg di recv ; altrimenti come argomento ; "LPOVERLAPPED lpOverlapped" di xp-api ReadFile ; s=0ra, 4P_fp, 8P_bu, 12P_len, 16P_cr, 20P_ovl ReadFile_r: %define @flag 12 %define @fd 16 mov edx, [esp+4] cmp edx, 0 je .0 mov eax, [edx+(a)fd] mov ecx, [edx+(a)flag] test ecx, 512 jnz .2 mov [esp+4], eax ; write fd jmp ReadFile ; here file ..0: mov ecx, [esp+16] ..1: cmp ecx, 0 je .e mov dword[ecx], 0 ..e: mov eax, 0 jmp short .f ..2: ; 4� par mov ecx, [esp+20] push ecx mov edx, [esp+12] ; r->bu c->len mov ecx, [esp+16] push ecx push edx push eax call recv ; here socket mov ecx, [esp+16] cmp eax, -1 je .1 cmp ecx, 0 je .f mov [ecx], eax ..f: %undef @flag %undef @fd ret 20 ; int WriteFile_r(FILE* fp, char* bu, ; uns len, uns* ncScritti, void* ovl) ; considero ovl se fp � un socket => come argomento falg di send ; altrimenti come argomento ; "LPOVERLAPPED lpOverlapped" di xp-api WriteFile ; s=0ra, 4P_fp, 8P_bu, 12P_len, 16P_cr, 20P_ovl WriteFile_r: %define @flag 12 %define @fd 16 mov edx, [esp+4] cmp edx, 0 je .0 mov eax, [edx+(a)fd] mov ecx, [edx+(a)flag] test ecx, 512 jnz .2 mov [esp+4], eax ; write fd jmp WriteFile ; here file ..0: mov ecx, [esp+16] ..1: cmp ecx, 0 je .e mov dword[ecx], 0 ..e: mov eax, 0 jmp short .f ..2: ; 4� par mov ecx, [esp+20] push ecx mov edx, [esp+12] ; r->bu c->len mov ecx, [esp+16] push ecx push edx push eax call send ; here socket mov ecx, [esp+16] cmp eax, -1 je .1 cmp ecx, 0 je .f mov [ecx], eax ..f: %undef @flag %undef @fd ret 20 /* int ReadFile_r(FILE* fp, char* bu, /* uns len, uns* ncLetti, void* ovl) /* considero ovl se fp � un socket => come argomento falg di recv /* altrimenti come argomento /* "LPOVERLAPPED lpOverlapped" di xp-api ReadFile /* s=0ra, 4P_fp, 8P_bu, 12P_len, 16P_cr, 20P_ovl ReadFile_r: << @flag=12, @fd=16 r=[s+4]; r==0#.0; a=[r+(a)fd]; c=[r+(a)flag]; c&512#.2; [s+4]=a; /* write fd jmp ReadFile; /* here file ..0: c=[s+16] ..1: c==0#.e; D*c=0; ..e: a=0; #.f ..2: c=[s+20]; < c; /* 4� par r=[s+12]; c=[s+16]; /* r->bu c->len recv(a, r, c); /* here socket c=[s+16]; a==-1#.1; c==0#.f; *c=a; ..f: >> @flag, @fd ret 20 /* int WriteFile_r(FILE* fp, char* bu, /* uns len, uns* ncScritti, void* ovl) /* considero ovl se fp � un socket => come argomento falg di send /* altrimenti come argomento /* "LPOVERLAPPED lpOverlapped" di xp-api WriteFile /* s=0ra, 4P_fp, 8P_bu, 12P_len, 16P_cr, 20P_ovl WriteFile_r: << @flag=12, @fd=16 r=[s+4]; r==0#.0; a=[r+(a)fd]; c=[r+(a)flag]; c&512#.2; [s+4]=a; /* write fd jmp WriteFile; /* here file ..0: c=[s+16] ..1: c==0#.e; D*c=0; ..e: a=0; #.f ..2: c=[s+20]; < c; /* 4� par r=[s+12]; c=[s+16]; /* r->bu c->len send(a, r, c); /* here socket c=[s+16]; a==-1#.1; c==0#.f; *c=a; ..f: >> @flag, @fd ret 20
From: Frank Kotler on 19 Dec 2007 06:49 Rosario wrote: .... > const char FAR * buf, FAR *? Maybe this makes sense for Windows - fs:???? - but it looks odd to me. Is that really what you want? Best, Frank
From: Rosario on 19 Dec 2007 09:02 In data Wed, 19 Dec 2007 11:49:23 GMT, Frank Kotler scrisse: >Rosario wrote: > >... >> const char FAR * buf, > >FAR *? Maybe this makes sense for Windows - fs:???? - but it looks odd >to me. Is that really what you want? yes all is ok that pointer is ok >Best, >Frank
From: Frank Kotler on 19 Dec 2007 09:21 Rosario wrote: > In data Wed, 19 Dec 2007 11:49:23 GMT, Frank Kotler scrisse: > > >>Rosario wrote: >> >>... >> >>> const char FAR * buf, >> >>FAR *? Maybe this makes sense for Windows - fs:???? - but it looks odd >>to me. Is that really what you want? > > > yes all is ok that pointer is ok Okay... doesn't appear to match the code... mov ecx, [esp+20] push ecx mov edx, [esp+12] ; r->bu c->len mov ecx, [esp+16] push ecx push edx push eax call send ; here socket Best, Frank
From: Rosario on 19 Dec 2007 12:15 In data Wed, 19 Dec 2007 14:21:35 GMT, Frank Kotler scrisse: >Rosario wrote: >> In data Wed, 19 Dec 2007 11:49:23 GMT, Frank Kotler scrisse: >> >> >>>Rosario wrote: >>> >>>... >>> >>>> const char FAR * buf, >>> >>>FAR *? Maybe this makes sense for Windows - fs:???? - but it looks odd >>>to me. Is that really what you want? >> >> >> yes all is ok that pointer is ok > >Okay... doesn't appear to match the code... > > mov ecx, [esp+20] > push ecx Afther the first push above the stack is +4 in eax there is "fd" > mov edx, [esp+12] ; r->bu c->len > mov ecx, [esp+16] > push ecx > push edx > push eax > call send ; here socket > >Best, >Frank
|
Next
|
Last
Pages: 1 2 Prev: Beth aka "BethStone21" Next: the screen light of my portable pc is off |