-
Notifications
You must be signed in to change notification settings - Fork 704
FreeBSD support #3398
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
FreeBSD support #3398
Changes from all commits
93729df
c6c6e4f
e7270f0
485e39e
b7a3bb3
795c611
3d1d358
8266590
86e0ded
37dec2f
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
@@ -0,0 +1,51 @@ | ||||||
//===----------------------------------------------------------------------===// | ||||||
// | ||||||
// This source file is part of the SwiftNIO open source project | ||||||
// | ||||||
// Copyright (c) 2017-2018 Apple Inc. and the SwiftNIO project authors | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
// Licensed under Apache License v2.0 | ||||||
// | ||||||
// See LICENSE.txt for license information | ||||||
// See CONTRIBUTORS.txt for the list of SwiftNIO project authors | ||||||
// | ||||||
// SPDX-License-Identifier: Apache-2.0 | ||||||
// | ||||||
//===----------------------------------------------------------------------===// | ||||||
#ifndef C_NIO_FREEBSD_H | ||||||
#define C_NIO_FREEBSD_H | ||||||
|
||||||
#ifdef __FreeBSD__ | ||||||
#include <sys/socket.h> | ||||||
#include <sys/ioctl.h> | ||||||
#include <time.h> | ||||||
#include <dirent.h> | ||||||
#include <sys/types.h> | ||||||
#include <sys/stat.h> | ||||||
#include <fts.h> | ||||||
#include <net/if_dl.h> | ||||||
|
||||||
extern const int CNIOFreeBSD_AT_EMPTY_PATH; | ||||||
|
||||||
extern const int CNIOFreeBSD_IPTOS_ECN_NOTECT; | ||||||
extern const int CNIOFreeBSD_IPTOS_ECN_MASK; | ||||||
extern const int CNIOFreeBSD_IPTOS_ECN_ECT0; | ||||||
extern const int CNIOFreeBSD_IPTOS_ECN_ECT1; | ||||||
extern const int CNIOFreeBSD_IPTOS_ECN_CE; | ||||||
extern const int CNIOFreeBSD_IPV6_RECVPKTINFO; | ||||||
extern const int CNIOFreeBSD_IPV6_PKTINFO; | ||||||
|
||||||
int CNIOFreeBSD_sendmmsg(int sockfd, struct mmsghdr *msgvec, unsigned int vlen, int flags); | ||||||
int CNIOFreeBSD_recvmmsg(int sockfd, struct mmsghdr *msgvec, unsigned int vlen, int flags, struct timespec *timeout); | ||||||
|
||||||
// cmsghdr handling | ||||||
struct cmsghdr *CNIOFreeBSD_CMSG_FIRSTHDR(const struct msghdr *); | ||||||
struct cmsghdr *CNIOFreeBSD_CMSG_NXTHDR(const struct msghdr *, const struct cmsghdr *); | ||||||
const void *CNIOFreeBSD_CMSG_DATA(const struct cmsghdr *); | ||||||
void *CNIOFreeBSD_CMSG_DATA_MUTABLE(struct cmsghdr *); | ||||||
size_t CNIOFreeBSD_CMSG_LEN(size_t); | ||||||
size_t CNIOFreeBSD_CMSG_SPACE(size_t); | ||||||
|
||||||
const char* CNIOFreeBSD_dirent_dname(struct dirent* ent); | ||||||
|
||||||
#endif // __FreeBSD__ | ||||||
#endif // C_NIO_FREEBSD_H |
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I erred on calling this just CNIOBSD in #3394. Would it be better to do the same here, so that we don't need to have one CNIO.* module per operating system? Or should I go and rename CNIOBSD to CNIOOpenBSD there? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Do the two have similar-enough libcs? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There are quite similar, especially due to pedigree, but there is definitely divergence, such as functionality in FreeBSD that OpenBSD does not have. |
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
@@ -0,0 +1,79 @@ | ||||||
//===----------------------------------------------------------------------===// | ||||||
// | ||||||
// This source file is part of the SwiftNIO open source project | ||||||
// | ||||||
// Copyright (c) 2017-2018 Apple Inc. and the SwiftNIO project authors | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
elsewhere too |
||||||
// Licensed under Apache License v2.0 | ||||||
// | ||||||
// See LICENSE.txt for license information | ||||||
// See CONTRIBUTORS.txt for the list of SwiftNIO project authors | ||||||
// | ||||||
// SPDX-License-Identifier: Apache-2.0 | ||||||
// | ||||||
//===----------------------------------------------------------------------===// | ||||||
#ifdef __FreeBSD__ | ||||||
#include <CNIOFreeBSD.h> | ||||||
#include <err.h> | ||||||
#include <sysexits.h> | ||||||
#include <stdlib.h> | ||||||
#include <limits.h> | ||||||
#include <errno.h> | ||||||
#include <fcntl.h> | ||||||
#include <assert.h> | ||||||
#include <arpa/inet.h> | ||||||
#include <netinet/ip.h> | ||||||
#include <netinet/in.h> | ||||||
#include <sys/uio.h> | ||||||
#include "dirent.h" | ||||||
|
||||||
int CNIOFreeBSD_sendmmsg(int sockfd, struct mmsghdr *msgvec, unsigned int vlen, int flags) { | ||||||
return sendmmsg(sockfd, msgvec, vlen, flags); | ||||||
} | ||||||
|
||||||
int CNIOFreeBSD_recvmmsg(int sockfd, struct mmsghdr *msgvec, unsigned int vlen, int flags, struct timespec *timeout) { | ||||||
return recvmmsg(sockfd, msgvec, vlen, flags, timeout); | ||||||
} | ||||||
|
||||||
struct cmsghdr *CNIOFreeBSD_CMSG_FIRSTHDR(const struct msghdr *mhdr) { | ||||||
assert(mhdr != NULL); | ||||||
return CMSG_FIRSTHDR(mhdr); | ||||||
} | ||||||
|
||||||
struct cmsghdr *CNIOFreeBSD_CMSG_NXTHDR(const struct msghdr *mhdr, const struct cmsghdr *cmsg) { | ||||||
assert(mhdr != NULL); | ||||||
assert(cmsg != NULL); // Not required by Darwin but Linux needs this so we should match. | ||||||
return CMSG_NXTHDR(mhdr, cmsg); | ||||||
} | ||||||
|
||||||
const void *CNIOFreeBSD_CMSG_DATA(const struct cmsghdr *cmsg) { | ||||||
assert(cmsg != NULL); | ||||||
return CMSG_DATA(cmsg); | ||||||
} | ||||||
|
||||||
void *CNIOFreeBSD_CMSG_DATA_MUTABLE(struct cmsghdr *cmsg) { | ||||||
assert(cmsg != NULL); | ||||||
return CMSG_DATA(cmsg); | ||||||
} | ||||||
|
||||||
size_t CNIOFreeBSD_CMSG_LEN(size_t payloadSizeBytes) { | ||||||
return CMSG_LEN(payloadSizeBytes); | ||||||
} | ||||||
|
||||||
size_t CNIOFreeBSD_CMSG_SPACE(size_t payloadSizeBytes) { | ||||||
return CMSG_SPACE(payloadSizeBytes); | ||||||
} | ||||||
|
||||||
const int CNIOFreeBSD_IPTOS_ECN_NOTECT = IPTOS_ECN_NOTECT; | ||||||
const int CNIOFreeBSD_IPTOS_ECN_MASK = IPTOS_ECN_MASK; | ||||||
const int CNIOFreeBSD_IPTOS_ECN_ECT0 = IPTOS_ECN_ECT0; | ||||||
const int CNIOFreeBSD_IPTOS_ECN_ECT1 = IPTOS_ECN_ECT1; | ||||||
const int CNIOFreeBSD_IPTOS_ECN_CE = IPTOS_ECN_CE; | ||||||
const int CNIOFreeBSD_IPV6_RECVPKTINFO = IPV6_RECVPKTINFO; | ||||||
const int CNIOFreeBSD_IPV6_PKTINFO = IPV6_PKTINFO; | ||||||
const int CNIOFreeBSD_AT_EMPTY_PATH = AT_EMPTY_PATH; | ||||||
|
||||||
const char* CNIOFreeBSD_dirent_dname(struct dirent* ent) { | ||||||
return ent->d_name; | ||||||
} | ||||||
|
||||||
#endif // __APPLE__ |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -1284,6 +1284,25 @@ extension FileSystem { | |
while offset < sourceInfo.size { | ||
// sendfile(2) limits writes to 0x7ffff000 in size | ||
let size = min(Int(sourceInfo.size) - offset, 0x7fff_f000) | ||
#if os(FreeBSD) | ||
var _offset: Int? = offset | ||
var _dOffset: Int? = nil | ||
let result = Syscall.copy_file_range( | ||
from: sourceFD, | ||
offset: &_offset, | ||
to: destinationFD, | ||
destOffset: &_dOffset, | ||
size: size, | ||
flags: 0 | ||
).mapError { errno in | ||
FileSystemError.copy_file_range( | ||
errno: errno, | ||
from: sourcePath, | ||
to: destinationPath, | ||
location: .here() | ||
) | ||
} | ||
#else | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can we factor out this split to a helper function? |
||
let result = Syscall.sendfile( | ||
to: destinationFD, | ||
from: sourceFD, | ||
|
@@ -1297,7 +1316,7 @@ extension FileSystem { | |
location: .here() | ||
) | ||
} | ||
|
||
#endif | ||
switch result { | ||
case let .success(bytesCopied): | ||
offset += bytesCopied | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These platforms do not require a historical NIOPosix dependency, as they did not compile before.