Skip to content
This repository has been archived by the owner on Jan 23, 2023. It is now read-only.
/ corefx Public archive

bottom part of serial port support on Unix #29033

Merged
merged 11 commits into from
Jul 5, 2018
1 change: 1 addition & 0 deletions src/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/Native/Unix/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -256,6 +256,7 @@ endfunction()
include(configure.cmake)

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

add_compile_options(-Weverything)
add_compile_options(-Wno-c++98-compat-pedantic)
Expand Down
22 changes: 22 additions & 0 deletions src/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)
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please add C

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 .)
18 changes: 18 additions & 0 deletions src/Native/Unix/System.IO.Ports.Native/pal_serial.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
// 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>


Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: we have one blank line elsewhere

/* Open device file in non-blocking mode and without controlling terminal */
int SerialPortOpen(const char * name)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As noted in another comment, we should represent file descriptors at the interop layer as intptr_t. As it's currently written, on a 64-bit platform there's potentially going to be corruption here, as this is going to return a 32-bit value and the managed code is expected a 64-bit value.

{
int result;
while ((result = open(name, O_RDWR | O_NOCTTY | O_CLOEXEC | O_NONBLOCK)) < 0 && errno == EINTR);
return result;
}

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: there are two extra blank lines at the end of this file, reduce it to one blank line?

12 changes: 12 additions & 0 deletions src/Native/Unix/System.IO.Ports.Native/pal_serial.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
// 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"

BEGIN_EXTERN_C
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This macro and its END_ counterpart are not defined anymore and can be removed. Now we are pure C.


int SerialPortOpen(const char * name);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We've generally prefixed all exports with the name of the library, e.g. SystemIoPortsNative_SerialPortOpen.


END_EXTERN_C