Skip to content

Commit

Permalink
Add a KErrNotOpen error to StdFuncs.h
Browse files Browse the repository at this point in the history
This makes it easier to differentiate between a generic socket failure
and a socket failure that was caused when a connection cannot be made.
  • Loading branch information
Colin Ward authored and hitman-codehq committed May 27, 2024
1 parent 8fbe6eb commit 0a36a1b
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 0 deletions.
1 change: 1 addition & 0 deletions StdFuncs.h
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,7 @@ typedef signed long long TInt64;
#define KErrWrite -23
#define KErrEof -25
#define KErrHostNotFound -26
#define KErrNotOpen -27

/* Useful macros for the WinMain() and main() functions, enabling them to be used */
/* without #ifdefs in portable code */
Expand Down
10 changes: 10 additions & 0 deletions StdSocket.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ RSocket::RSocket()
* @return KErrNone if successful
* @return KErrGeneral if the socket could not be opened
* @return KErrHostNotFound if the host could not be resolved
* @return KErrNotOpen if a connection to the remote server could not be made
*/

int RSocket::open(const char *a_host, unsigned short a_port)
Expand Down Expand Up @@ -95,6 +96,10 @@ int RSocket::open(const char *a_host, unsigned short a_port)
{
retVal = KErrNone;
}
else
{
retVal = KErrNotOpen;
}
}
else
{
Expand All @@ -115,6 +120,11 @@ int RSocket::open(const char *a_host, unsigned short a_port)
}
}

if (retVal != KErrNone)
{
close();
}

return retVal;
}

Expand Down

0 comments on commit 0a36a1b

Please sign in to comment.