Changeset - r25686:fb6d0e17cffc
[Not reviewed]
master
0 2 0
rubidium42 - 3 years ago 2021-06-13 19:41:07
rubidium@openttd.org
Codechange: [Network] Let NetworkError return its std::string instead of a C-string
2 files changed with 3 insertions and 3 deletions:
0 comments (0 inline, 0 general)
src/network/core/os_abstraction.cpp
Show inline comments
 
@@ -73,13 +73,13 @@ bool NetworkError::IsConnectInProgress()
 
}
 

	
 
/**
 
 * Get the string representation of the error message.
 
 * @return The string representation that will get overwritten by next calls.
 
 */
 
const char *NetworkError::AsString() const
 
const std::string &NetworkError::AsString() const
 
{
 
	if (this->message.empty()) {
 
#if defined(_WIN32)
 
		char buffer[512];
 
		if (FormatMessageA(FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS, NULL, this->error,
 
			MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), buffer, sizeof(buffer), NULL) == 0) {
 
@@ -94,13 +94,13 @@ const char *NetworkError::AsString() con
 
		 * variant always fills the buffer. This makes the behaviour too erratic to work with. */
 
		static std::mutex mutex;
 
		std::lock_guard<std::mutex> guard(mutex);
 
		this->message.assign(strerror(this->error));
 
#endif
 
	}
 
	return this->message.c_str();
 
	return this->message;
 
}
 

	
 
/**
 
 * Check whether an error was actually set.
 
 * @return True iff an error was set.
 
 */
src/network/core/os_abstraction.h
Show inline comments
 
@@ -26,13 +26,13 @@ public:
 
	NetworkError(int error);
 

	
 
	bool HasError() const;
 
	bool WouldBlock() const;
 
	bool IsConnectionReset() const;
 
	bool IsConnectInProgress() const;
 
	const char *AsString() const;
 
	const std::string &AsString() const;
 

	
 
	static NetworkError GetLast();
 
};
 

	
 
/* Include standard stuff per OS */
 

	
0 comments (0 inline, 0 general)