Class ErrnoHandler

java.lang.Object
express.mvp.myra.transport.iouring.ErrnoHandler

public final class ErrnoHandler extends Object
Utility class for handling Linux errno codes in io_uring operations.

This class maps native Linux error codes to meaningful Java exceptions with actionable recovery hints. It is essential for debugging io_uring operations where completion queue entries (CQEs) return negative errno values on failure.

Common Error Scenarios

Errno codes and their meanings
ErrnoNameMeaningRecovery
11EAGAINResource temporarily unavailableRetry operation
32EPIPEBroken pipeReconnect
104ECONNRESETConnection reset by peerReconnect
110ETIMEDOUTConnection timed outCheck network, retry
111ECONNREFUSEDConnection refusedVerify server running

Usage Example

int result = LibUring.cqeGetRes(cqe);
if (result < 0) {
    if (ErrnoHandler.isRetryable(result)) {
        // Retry the operation
    } else if (ErrnoHandler.isConnectionLost(result)) {
        // Reconnect
    } else {
        throw ErrnoHandler.fromErrno(result, "send");
    }
}
See Also:
  • Method Details

    • fromErrno

      public static TransportException fromErrno(int errno, String operation)
      Creates a TransportException from an errno code with context.

      The exception message includes the operation name, error description, and actionable recovery hints for common errors.

      Parameters:
      errno - the Linux errno value (may be negative, will be converted to absolute)
      operation - description of the failed operation (e.g., "send", "recv", "connect")
      Returns:
      a TransportException with descriptive message and recovery hints
    • isRetryable

      public static boolean isRetryable(int errno)
      Checks if the errno indicates a retryable (transient) error.

      Retryable errors are temporary conditions that may succeed on retry, such as resource temporarily unavailable or operation in progress.

      Parameters:
      errno - the Linux errno value (may be negative)
      Returns:
      true if the operation should be retried
    • isConnectionLost

      public static boolean isConnectionLost(int errno)
      Checks if the errno indicates the connection was lost.

      Connection loss requires reconnection to recover. This includes broken pipe, connection reset, and timeout errors.

      Parameters:
      errno - the Linux errno value (may be negative)
      Returns:
      true if the connection was lost and reconnection is needed
    • isConnectionRefused

      public static boolean isConnectionRefused(int errno)
      Checks if the errno indicates the connection was refused.

      Connection refused means no service is listening on the target port. This typically requires verifying the server is running before retrying.

      Parameters:
      errno - the Linux errno value (may be negative)
      Returns:
      true if the connection was refused