Skip to content

Commit

Permalink
bottom part of serial port support on Unix (dotnet/corefx#29033)
Browse files Browse the repository at this point in the history
* bottom part of serial port support

* small cleanup

* feedback from reviews

* remove previous changes to System.Native

* feedback from review

* use consistently int32_t

* update names and types based on feedback

* feedback from kasper3


Commit migrated from dotnet/corefx@83753bc
  • Loading branch information
wfurt committed Jul 5, 2018
1 parent b251c61 commit 286b4f1
Show file tree
Hide file tree
Showing 9 changed files with 621 additions and 0 deletions.
1 change: 1 addition & 0 deletions src/libraries/Common/src/Interop/Unix/Interop.Libraries.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ internal static partial class Libraries
internal const string NetSecurityNative = "System.Net.Security.Native";
internal const string CryptoNative = "System.Security.Cryptography.Native.OpenSsl";
internal const string CompressionNative = "System.IO.Compression.Native";
internal const string IOPortsNative = "System.IO.Ports.Native";
internal const string Libdl = "libdl";
}
}
1 change: 1 addition & 0 deletions src/libraries/Native/Unix/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -238,6 +238,7 @@ endfunction()
include(configure.cmake)

add_subdirectory(System.IO.Compression.Native)
add_subdirectory(System.IO.Ports.Native)

add_compile_options(-Weverything)

Expand Down
22 changes: 22 additions & 0 deletions src/libraries/Native/Unix/System.IO.Ports.Native/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
project(System.IO.Ports.Native C)

add_library(System.IO.Ports.Native
SHARED
pal_termios.c
pal_serial.c
${VERSION_FILE_PATH}
)

add_library(System.IO.Ports.Native-Static
STATIC
pal_termios.c
pal_serial.c
${VERSION_FILE_PATH}
)

# Disable the "lib" prefix and override default name
set_target_properties(System.IO.Ports.Native-Static PROPERTIES PREFIX "")
set_target_properties(System.IO.Ports.Native-Static PROPERTIES OUTPUT_NAME System.IO.Ports.Native CLEAN_DIRECT_OUTPUT 1)

install_library_and_symbols (System.IO.Ports.Native)
install (TARGETS System.IO.Ports.Native-Static DESTINATION .)
16 changes: 16 additions & 0 deletions src/libraries/Native/Unix/System.IO.Ports.Native/pal_serial.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.

#include "pal_types.h"
#include <fcntl.h>
#include <errno.h>
#include <pal_serial.h>

/* Open device file in non-blocking mode and without controlling terminal */
intptr_t SystemIoPortsNative_SerialPortOpen(const char * name)
{
intptr_t result;
while ((result = open(name, O_RDWR | O_NOCTTY | O_CLOEXEC | O_NONBLOCK)) < 0 && errno == EINTR);
return result;
}
9 changes: 9 additions & 0 deletions src/libraries/Native/Unix/System.IO.Ports.Native/pal_serial.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.

#include "pal_types.h"
#include "pal_compiler.h"

DLLEXPORT intptr_t SystemIoPortsNative_SerialPortOpen(const char * name);

0 comments on commit 286b4f1

Please sign in to comment.