Recent

Author Topic: fpsockets error: 10047  (Read 1616 times)

rvk

  • Hero Member
  • *****
  • Posts: 6924
Re: fpsockets error: 10047
« Reply #15 on: December 11, 2025, 09:27:46 am »
@tetrates
A trunk from a year old is not a trunk...
And what is it? Release?  :D
It's "trunk from a year ago"  ;)

I agree you shouldn't say you are on "trunk" (if it's an old compile) because that implies the latest development version, but you can say "trunk from a year ago". But it's best to also specify a date or month so you indicate that there could have been a regression since that version.

You can also copy paste the compile info in the about.
Lazarus 4.99 (rev main_4_99-2435-g769b7fdc4f) FPC 3.3.1 x86_64-win64-win32/win64

Which will be:
Revision: 769b7fdc4f4838e178f91178ce3c7cb482306b85
Date: 30-07-2025 12:04:22
« Last Edit: December 11, 2025, 09:33:58 am by rvk »

tetrastes

  • Hero Member
  • *****
  • Posts: 733
Re: fpsockets error: 10047
« Reply #16 on: December 11, 2025, 09:35:43 am »
I had written this quite clearly:
 
In my one-year-old trunk it's OK:

had not I?
If I thought that more exact info was relevant, I would added it.


Thaddy

  • Hero Member
  • *****
  • Posts: 18703
  • To Europe: simply sell USA bonds: dollar collapses
Re: fpsockets error: 10047
« Reply #17 on: December 11, 2025, 09:48:41 am »
Thanks bytebites. That will help.
If Europe sells their USA bonds the USD will collapse. Europe can affort that given average state debts. The USA can't affort that. Just an advice...

rvk

  • Hero Member
  • *****
  • Posts: 6924
Re: fpsockets error: 10047
« Reply #18 on: December 11, 2025, 09:50:08 am »
I had written this quite clearly:
In my one-year-old trunk it's OK:
had not I?
You did, which was correct.

Warfley

  • Hero Member
  • *****
  • Posts: 2037
Re: fpsockets error: 10047
« Reply #19 on: December 12, 2025, 01:32:51 pm »
Error Code 10047 is WSAEAFNOSUPPORT:
Code: Pascal  [Select][+][-]
  1. Address family not supported by protocol family.
  2.     An address incompatible with the requested protocol was used. All sockets are created with an associated address family (that is, AF_INET for Internet Protocols) and a generic protocol type (that is, SOCK_STREAM). This error is returned if an incorrect protocol is explicitly requested in the socket call, or if an address of the wrong family is used for a socket, for example, in sendto.

This means that something is wrong internally with the conversion of the TNetworkAddress to the TAddressUnion block used for the sockets call. Need to look into that hopefully somewhen this weekend. (Also I'm pretty sure when reading the code just now of ReceiveStr I've found a bug anyways)

To answer the other questions:
Quote
1. The ReceiveStr function does not have a parameter like TimeOut. So will it be blocked until a string come?
ReceiveStr does not read a string per-se, it will just read what is available and return this byte sequence as a string. With Datagrams it's rather simple because you'll just receive the contents of the last datagram as a string. With a Stream (TCP) it's a bit more complicated, because if you received multiple sends since the last receive, you'll just read everything the OS has buffered so far
Quote
2. I guess SetNonBlocking(sock, True) and ReceiveStrFromNonBlocking will check if there any data in the buffer, and it will return immediately if the buffer is empty, And then I need to implement timeout function by myself, Am I right?
Yeah if you want to deal with non blocking sockets. Otherwise look at these functions:
Code: Pascal  [Select][+][-]
  1. // Timeout in MS
  2. {$IFDEF HAVE_SELECT_CALL}
  3. function DataAvailable(const SocketArray: specialize TArray<TFPSocket>; TimeOut: Integer = 0): specialize TArray<TFPSocket>; overload;
  4. function DataAvailable(const ASocket: TFPSocket; TimeOut: Integer = 0): Boolean; overload; //inline;
  5. function DataAvailable(const SocketArray: array of TFPSocket; TimeOut: Integer = 0): specialize TArray<TFPSocket>; overload; inline;
  6. {$ENDIF}
  7.  
  8. function BytesAvailable(const ASocket: TFPSocket): SizeInt;
  9.  
I'm also pretty sure I made a test for it somewhere, but I'm not sure where 😅
Quote
3. How to enlarge the buffer size?
Do you mean the OS buffer? If so, fpsockets is just a very thin layer over the berkley sockets API. Not all functionalities are provided by it, and in those cases you just need to do the raw ioctl calls (or other apis). Just grab the FD field of the TFPSocket record and pass it to the system APIs.

Note: You can find a few more examples over here (it's the repository before I contributed it to fcl, so it may be slightly outdated): https://github.com/Warfley/PasSimpleSockets/tree/master/examples

parcel

  • Full Member
  • ***
  • Posts: 145
Re: fpsockets error: 10047
« Reply #20 on: December 13, 2025, 04:03:56 pm »
I post small patch on bug tracker.
https://gitlab.com/-/project/28644964/uploads/fc662c10d49e4e69cabfe52980160c5b/41536_fpsockets.pp.diff

There are missing update socket addr record on functions at last trunk updating.


With my patch. pass tfpsock2.
Quote
PS F:\fpcupdeluxe\fpcsrc\packages\fcl-net\tests> ./tfpsock2
Testing IPv4Test... Success!
Testing IPv6Test... Success!
Testing DualStackTest... Success!
Testing DataAvailableTest... Success!
Testing ReceiveArrayTest... Success!
Testing ChunkTest... Success!
Testing UDPFragmentationTest... Success!
Testing NonBlockingTest... Success!
Testing FragmentationTest... Success!
Testing FragmentedArrayTest... Success!


 

TinyPortal © 2005-2018