[haiku-commits] Re: BRANCH pdziepak-github.nfs4 - src/add-ons/kernel/file_systems/nfs4

  • From: Axel Dörfler <axeld@xxxxxxxxxxxxxxxx>
  • To: haiku-commits@xxxxxxxxxxxxx
  • Date: Thu, 12 Jul 2012 17:53:23 +0200

On 12.07.2012 00:49, pdziepak-github.nfs4 wrote:
@@ -242,7 +243,7 @@ ConnectionStream::Receive(void** pbuffer, uint32* psize)

                received = 0;
                do {
-                       result = recv(fSock, (uint8*)buffer + size + received,
+                       result = recv(fSocket, (uint8*)buffer + size + received,
                                                        record_size - received, 
0);

Unless my mail client messed it up, the second line looks awfully far indented. Also, record_size -> recordSize.

-       status_t result = connect(fSock, (struct sockaddr*)&fServerAddress,
+       status_t result = connect(fSocket, (struct sockaddr*)&fServerAddress,
                                                                
fServerAddress.sin_len);

Indentation looks strange here as well; the second line should only be indented a single tab in comparison to the current indentation level.

  bool
  ServerAddress::operator==(const ServerAddress& address)
  {
-       return fAddress == address.fAddress && fPort == address.fPort
-                       && fProtocol == address.fProtocol;

Out of curiosity: what are the fPort/fProtocol fields used for?

+       switch (reinterpret_cast<const sockaddr*>(&fServerAddress)->sa_family) {
+               case AF_INET:
+                       addressSize = sizeof(sockaddr_in);
+                       break;
+               case AF_INET6:
+                       addressSize = sizeof(sockaddr_in6);
+                       break;
+               default:
+                       return B_BAD_VALUE;
+       }

Maybe move that code into a ServerAddress::Size() method? Besides that, getsockname() shouldn't mind if the size given is larger than the size it needs to store the information (although that part is not portable, as other platforms can be strict about this).

Maybe ServerAddress could be a light-weight version mix of BNetworkAddress/BNetworkAddressResolver instead? And since there is nothing server specific about ServerAddress, the class could then be renamed, too :-)

+       socklen_t addressSize;
+       switch (address.sa_family) {
+               case AF_INET:
+                       addressSize = sizeof(sockaddr_in);
+                       break;
+               case AF_INET6:
+                       addressSize = sizeof(sockaddr_in6);
+                       break;

You could at least get rid of this code duplication this way :-)

> @@ -352,12 +365,15 @@ Connection::Connect(Connection **_connection, const ServerAddress& address)
>  status_t
>  Connection::Connect()
>  {
> -  switch (fProtocol) {
> +  const sockaddr& address =
> +          *reinterpret_cast<const sockaddr*>(&fServerAddress);

The '=' goes to the next line.

Anyway, nice work!

Bye,
   Axel.

Other related posts: