Skip to content

Commit

Permalink
some renames
Browse files Browse the repository at this point in the history
  • Loading branch information
prezaei committed Sep 25, 2024
1 parent 3e3d631 commit 1cef822
Show file tree
Hide file tree
Showing 4 changed files with 85 additions and 86 deletions.
32 changes: 16 additions & 16 deletions src/Interprocess/Semaphore/Linux/Interop.cs
Original file line number Diff line number Diff line change
Expand Up @@ -55,13 +55,13 @@ internal static IntPtr CreateOrOpenSemaphore(string name, uint initialCount)
{
EINVAL => new ArgumentException($"The initial count cannot be greater than {SEMVALUEMAX}.", nameof(initialCount)),
ENAMETOOLONG => new ArgumentException($"The specified semaphore name is too long.", nameof(name)),
EACCES => new PosixSempahoreUnauthorizedAccessException(),
EEXIST => new PosixSempahoreExistsException(),
EACCES => new PosixSemaphoreUnauthorizedAccessException(),
EEXIST => new PosixSemaphoreExistsException(),
EINTR => new OperationCanceledException(),
ENFILE => new PosixSempahoreException("Too many semaphores or file descriptors are open on the system."),
EMFILE => new PosixSempahoreException("Too many semaphores or file descriptors are open by this process."),
ENFILE => new PosixSemaphoreException("Too many semaphores or file descriptors are open on the system."),
EMFILE => new PosixSemaphoreException("Too many semaphores or file descriptors are open by this process."),
ENOMEM => new InsufficientMemoryException(),
_ => new PosixSempahoreException(Error),
_ => new PosixSemaphoreException(Error),
};
}

Expand All @@ -72,9 +72,9 @@ internal static void Release(IntPtr handle)

throw Error switch
{
EINVAL => new InvalidPosixSempahoreException(),
EINVAL => new InvalidPosixSemaphoreException(),
EOVERFLOW => new SemaphoreFullException(),
_ => new PosixSempahoreException(Error),
_ => new PosixSemaphoreException(Error),
};
}

Expand All @@ -97,9 +97,9 @@ private static void Wait(IntPtr handle)

throw Error switch
{
EINVAL => new InvalidPosixSempahoreException(),
EINVAL => new InvalidPosixSemaphoreException(),
EINTR => new OperationCanceledException(),
_ => new PosixSempahoreException(Error),
_ => new PosixSemaphoreException(Error),
};
}

Expand All @@ -111,9 +111,9 @@ private static bool Wait(IntPtr handle, PosixTimespec timeout)
return Error switch
{
ETIMEDOUT => false,
EINVAL => throw new InvalidPosixSempahoreException(),
EINVAL => throw new InvalidPosixSemaphoreException(),
EINTR => throw new OperationCanceledException(),
_ => throw new PosixSempahoreException(Error),
_ => throw new PosixSemaphoreException(Error),
};
}

Expand All @@ -124,8 +124,8 @@ internal static void Close(IntPtr handle)

throw Error switch
{
EINVAL => new InvalidPosixSempahoreException(),
_ => new PosixSempahoreException(Error),
EINVAL => new InvalidPosixSemaphoreException(),
_ => new PosixSemaphoreException(Error),
};
}

Expand All @@ -137,9 +137,9 @@ internal static void Unlink(string name)
throw Error switch
{
ENAMETOOLONG => new ArgumentException($"The specified semaphore name is too long.", nameof(name)),
EACCES => new PosixSempahoreUnauthorizedAccessException(),
ENOENT => new PosixSempahoreNotExistsException(),
_ => new PosixSempahoreException(Error),
EACCES => new PosixSemaphoreUnauthorizedAccessException(),
ENOENT => new PosixSemaphoreNotExistsException(),
_ => new PosixSemaphoreException(Error),
};
}
}
Expand Down
39 changes: 19 additions & 20 deletions src/Interprocess/Semaphore/MacOS/Interop.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,7 @@ internal static class Interop
{
private const string Lib = "libSystem.dylib";
private const int SEMVALUEMAX = 32767;
private const int OCREAT = 0x0200; // create the semaphore if it does not exist

private const int OCREAT = 0x0200; // create the semaphore if it does not exist
private const int ENOENT = 2; // The named semaphore does not exist.
private const int EINTR = 4; // Semaphore operation was interrupted by a signal.
private const int EDEADLK = 11; // A deadlock was detected.
Expand Down Expand Up @@ -58,13 +57,13 @@ internal static IntPtr CreateOrOpenSemaphore(string name, uint initialCount)
{
EINVAL => new ArgumentException($"The initial count cannot be greater than {SEMVALUEMAX}.", nameof(initialCount)),
ENAMETOOLONG => new ArgumentException($"The specified semaphore name is too long.", nameof(name)),
EACCES => new PosixSempahoreUnauthorizedAccessException(),
EEXIST => new PosixSempahoreExistsException(),
EACCES => new PosixSemaphoreUnauthorizedAccessException(),
EEXIST => new PosixSemaphoreExistsException(),
EINTR => new OperationCanceledException(),
ENFILE => new PosixSempahoreException("Too many semaphores or file descriptors are open on the system."),
EMFILE => new PosixSempahoreException("Too many semaphores or file descriptors are open by this process."),
ENFILE => new PosixSemaphoreException("Too many semaphores or file descriptors are open on the system."),
EMFILE => new PosixSemaphoreException("Too many semaphores or file descriptors are open by this process."),
ENOMEM => new InsufficientMemoryException(),
_ => new PosixSempahoreException(Error),
_ => new PosixSemaphoreException(Error),
};
}

Expand All @@ -75,9 +74,9 @@ internal static void Release(IntPtr handle)

throw Error switch
{
EINVAL => new InvalidPosixSempahoreException(),
EINVAL => new InvalidPosixSemaphoreException(),
EOVERFLOW => new SemaphoreFullException(),
_ => new PosixSempahoreException(Error),
_ => new PosixSemaphoreException(Error),
};
}

Expand Down Expand Up @@ -109,10 +108,10 @@ private static void Wait(IntPtr handle)

throw Error switch
{
EINVAL => new InvalidPosixSempahoreException(),
EDEADLK => new PosixSempahoreException($"A deadlock was detected attempting to wait on a semaphore."),
EINVAL => new InvalidPosixSemaphoreException(),
EDEADLK => new PosixSemaphoreException($"A deadlock was detected attempting to wait on a semaphore."),
EINTR => new OperationCanceledException(),
_ => new PosixSempahoreException(Error),
_ => new PosixSemaphoreException(Error),
};
}

Expand All @@ -124,10 +123,10 @@ private static bool TryWait(IntPtr handle)
return Error switch
{
EAGAIN => false,
EINVAL => throw new InvalidPosixSempahoreException(),
EDEADLK => throw new PosixSempahoreException($"A deadlock was detected attempting to wait on a semaphore."),
EINVAL => throw new InvalidPosixSemaphoreException(),
EDEADLK => throw new PosixSemaphoreException($"A deadlock was detected attempting to wait on a semaphore."),
EINTR => throw new OperationCanceledException(),
_ => throw new PosixSempahoreException(Error),
_ => throw new PosixSemaphoreException(Error),
};
}

Expand All @@ -138,8 +137,8 @@ internal static void Close(IntPtr handle)

throw Error switch
{
EINVAL => new InvalidPosixSempahoreException(),
_ => new PosixSempahoreException(Error),
EINVAL => new InvalidPosixSemaphoreException(),
_ => new PosixSemaphoreException(Error),
};
}

Expand All @@ -151,9 +150,9 @@ internal static void Unlink(string name)
throw Error switch
{
ENAMETOOLONG => new ArgumentException($"The specified semaphore name is too long.", nameof(name)),
EACCES => new PosixSempahoreUnauthorizedAccessException(),
ENOENT => new PosixSempahoreNotExistsException(),
_ => new PosixSempahoreException(Error),
EACCES => new PosixSemaphoreUnauthorizedAccessException(),
ENOENT => new PosixSemaphoreNotExistsException(),
_ => new PosixSemaphoreException(Error),
};
}
}
Expand Down
50 changes: 50 additions & 0 deletions src/Interprocess/Semaphore/Posix/PosixSemaphoreException.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
using System;

namespace Cloudtoid.Interprocess.Semaphore.Posix
{
internal class PosixSemaphoreException
: Exception
{
public PosixSemaphoreException(string message)
: base(message)
{
}

public PosixSemaphoreException(int errorCode)
: base($"Semaphore exception with inner code = {errorCode}")
{
}
}

internal class InvalidPosixSemaphoreException : PosixSemaphoreException
{
public InvalidPosixSemaphoreException()
: base($"The specified semaphore does not exist or it is invalid.")
{
}
}

internal class PosixSemaphoreNotExistsException : PosixSemaphoreException
{
public PosixSemaphoreNotExistsException()
: base($"The specified semaphore does not exist.")
{
}
}

internal class PosixSemaphoreExistsException : PosixSemaphoreException
{
public PosixSemaphoreExistsException()
: base("A Semaphore with this name already exists")
{
}
}

internal class PosixSemaphoreUnauthorizedAccessException : PosixSemaphoreException
{
public PosixSemaphoreUnauthorizedAccessException()
: base("The semaphore exists, but the caller does not have permission to open it.")
{
}
}
}
50 changes: 0 additions & 50 deletions src/Interprocess/Semaphore/Posix/PosixSempahoreException.cs

This file was deleted.

0 comments on commit 1cef822

Please sign in to comment.