Newsgroups : Borland : borland.public.delphi.internet.winsock : 2006 Mar : Re: SendBuf
| Subject: | Re: SendBuf |
| Posted by: | "Ivan Kossey" (spamers.sollen.sterben@cablenet.de) |
| Date: | Thu, 23 Mar 2006 21:04:25 |
Thank You, Remy!
"Remy Lebeau (TeamB)" <no.spam@no.spam.com> schrieb im Newsbeitrag
news:4422f11d$1@newsgroups.borland.com...
>
> "Ivan Kossey" <spamers.sollen.sterben@cablenet.de> wrote in message
> news:4422d0b1@newsgroups.borland.com...
>
>> It is not mentioned
>> 1. What is the type of buf (PChar, string,...)?
>
> Actually, it does. It is an untyped parameter, analagous to a Pointer.
> Which means that you can pass anything to it that represents a memory
> address.
>
>> 2. What integer value returns the function?
>
> It returns how many bytes were actually accepted. It can be less then the
> amount specified by the bufsize parameter, if there is not enough room for
> the entire buffer. If the the return value indicates that not all of the
> buffer was sent, then you have to adjust your input pointer accordingly
> and
> call SendBuf() again to sent the remaining data.
>
> Here are a few examples:
>
> var
> buffer: array[0..11] of Byte;
> idx, sent: Integer;
> begin
> // fill the buffer as needed ...
> idx := 0;
> while idx < SizeOf(buffer) do
> begin
> sent := ...SendBuf(buffer[idx], SizeOf(buffer)-idx);
> if sent = -1 then begin // blocking send, resend
> Sleep(50);
> Continue;
> end;
> if sent = 0 then Break; // disconnected
> Inc(idx, sent);
> end;
> end;
>
>
> var
> buffer: array of Byte;
> idx, sent: Integer;
> begin
> SetLength(buffer, 12);
> // fill the buffer as needed ...
> idx := 0;
> while idx < Length(buffer) do
> begin
> sent := ...SendBuf(buffer[idx], Length(buffer)-idx);
> if sent = -1 then begin // blocking send, resend
> Sleep(50);
> Continue;
> end;
> if sent = 0 then Break; // disconnected
> Inc(idx, sent);
> end;
> end;
>
>
> var
> s: String;
> idx, sent: Integer;
> begin
> s := 'something';
> idx := 0;
> while idx < Length(s) do
> begin
> sent := ...SendBuf(PChar(s)+idx, Length(s)-idx);
> if sent = -1 then begin // blocking send, resend
> Sleep(50);
> Continue;
> end;
> if sent = 0 then Break; // disconnected
> Inc(idx, sent);
> end;
> end;
>
>
> var
> value: Integer;
> ptr: PByte;
> idx, sent: Integer;
> begin
> value := 12345;
> idx := 0;
> while idx < SizeOf(i) do
> begin
> sent := ...SendBuf(PByte(@value)[idx], SizeOf(value)-idx);
> if sent = -1 then begin // blocking send, resend
> Sleep(50);
> Continue;
> end;
> if sent = 0 then Break; // disconnected
> Inc(idx, sent);
> end;
> end;
>
>
> Gambit
none