Skip to content
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

Implement UringSystem and FS2 Sockets using netty io_uring API #78

Open
wants to merge 201 commits into
base: feature/jvm
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 185 commits
Commits
Show all changes
201 commits
Select commit Hold shift + click to select a range
786abd1
Add unsafe to jvm
antoniojimeneznieto May 30, 2023
16e6305
Add uring files from native
antoniojimeneznieto May 30, 2023
46f3dc8
Import Netty io_uring
antoniojimeneznieto May 31, 2023
fd2c459
Expose Native methods and RingBuffer
antoniojimeneznieto Jun 5, 2023
be118ef
Add Completion and Submission Queues
antoniojimeneznieto Jun 5, 2023
6e9ea0a
Add RingBuffer
antoniojimeneznieto Jun 5, 2023
88f02e7
Add header
antoniojimeneznieto Jun 5, 2023
7be84f6
Replace Ptr with SubmissionQueue
antoniojimeneznieto Jun 5, 2023
08eb506
Call UringSystem as pollingSystem
antoniojimeneznieto Jun 5, 2023
486a164
Add values for Completion and Submission queues
antoniojimeneznieto Jun 5, 2023
09b79cb
Start implementation of Poller
antoniojimeneznieto Jun 5, 2023
d767b7b
Add Companion Object
antoniojimeneznieto Jun 8, 2023
408252c
Sketch additional methods needed
antoniojimeneznieto Jun 8, 2023
3cb48c7
Sketch reimplementation of UringSystem
antoniojimeneznieto Jun 8, 2023
d6e7d76
Add POLLIN & POLLOUT
antoniojimeneznieto Jun 8, 2023
2b0f5aa
Remove FileDescriptor Poller and Handle
antoniojimeneznieto Jun 8, 2023
0d1ae85
Formatting
antoniojimeneznieto Jun 8, 2023
18dd9f3
Formatting
antoniojimeneznieto Jun 8, 2023
3fdda21
Add prepCancel
antoniojimeneznieto Jun 8, 2023
f294e33
Sketch a plan for manipulating the Data
antoniojimeneznieto Jun 10, 2023
1bc768e
Implement userData and setData
antoniojimeneznieto Jun 20, 2023
57b6ff3
Implement poll and adapt get & set Data
antoniojimeneznieto Jun 20, 2023
6af5dbc
Add documentation for Ring and Completion Queue
antoniojimeneznieto Jun 20, 2023
ca5a434
Add UringSystemSuite
antoniojimeneznieto Jun 20, 2023
33eeebb
Add OP for read and write
antoniojimeneznieto Jun 20, 2023
85c8699
Isolate netty package in one file
antoniojimeneznieto Jul 3, 2023
8445b01
Update Callbacks Map
antoniojimeneznieto Jul 3, 2023
21ca1e7
Create IORuntime with Uring polling System
antoniojimeneznieto Jul 4, 2023
4d432c4
Update the poll processing and timeout
antoniojimeneznieto Jul 4, 2023
50514ee
Add submission test
antoniojimeneznieto Jul 5, 2023
118ad86
Reimplement UringSystem using netty api
antoniojimeneznieto Jul 10, 2023
5f74452
Remove Cb from SQ
antoniojimeneznieto Jul 11, 2023
54dde73
Add NOP test
antoniojimeneznieto Jul 11, 2023
42fe04b
Add poll
antoniojimeneznieto Jul 11, 2023
18e2466
Remove Socket
antoniojimeneznieto Jul 11, 2023
6a243be
Format file & add print for debugging
antoniojimeneznieto Jul 11, 2023
2f37b74
Add parallel submission tests
antoniojimeneznieto Jul 11, 2023
79e9f03
Add feedback comments
antoniojimeneznieto Jul 11, 2023
19249e4
Update the Cancel method
antoniojimeneznieto Jul 12, 2023
285782f
add send_msg_ring and all the OP availables
antoniojimeneznieto Jul 12, 2023
07629a9
Use the OP object to select an operation
antoniojimeneznieto Jul 12, 2023
27cb02b
Remove encoder
antoniojimeneznieto Jul 12, 2023
4d5e8dc
Encapsulate the SubmissionQueue in poller
antoniojimeneznieto Jul 12, 2023
51cfed9
Reorder poll flow
antoniojimeneznieto Jul 12, 2023
a842e88
Use java BitSet, handle nanos == -1 and add Cancel
antoniojimeneznieto Jul 13, 2023
348f684
Use OP from netty and add cancellation test
antoniojimeneznieto Jul 13, 2023
dfbc637
Remove cancellation test
antoniojimeneznieto Jul 13, 2023
9c23c2b
Comment the problem with nanos == -1
antoniojimeneznieto Jul 13, 2023
070655b
Abstract the handleCallback
antoniojimeneznieto Jul 14, 2023
6c9f301
Add documentation
antoniojimeneznieto Jul 14, 2023
28ffbca
Rename UringSystemSuite & Reformat IORuntime
antoniojimeneznieto Jul 14, 2023
4667297
Add cancel and sendMsgRing to Poller
antoniojimeneznieto Jul 16, 2023
032a279
Remove unused tests
antoniojimeneznieto Jul 17, 2023
0e7365c
Rewrite poll system and add debug mode
antoniojimeneznieto Jul 17, 2023
d42665d
Move OP to util and rework on SendMsgRing
antoniojimeneznieto Jul 22, 2023
d273a5e
Add default values to call and bracket
antoniojimeneznieto Jul 22, 2023
c96fc7d
Implement UringSocket
antoniojimeneznieto Jul 22, 2023
4cce052
Add TODO
antoniojimeneznieto Jul 22, 2023
c0281fa
Move the OP to util
antoniojimeneznieto Jul 22, 2023
be3bf0f
Add default value
antoniojimeneznieto Jul 22, 2023
ecb3e58
Add MsgHdr and MsgHdrArray classes
antoniojimeneznieto Jul 24, 2023
d52b7e7
Add Iov class
antoniojimeneznieto Jul 24, 2023
7fa8b05
Add LinuxSocket
antoniojimeneznieto Jul 25, 2023
37e713a
Implement localAddress
antoniojimeneznieto Jul 25, 2023
49ba2b1
Add Companion Object for LinuxSocket
antoniojimeneznieto Jul 25, 2023
2215a4d
Add fd method in LinuxSocket
antoniojimeneznieto Jul 25, 2023
a518d30
Add UringNetwork
antoniojimeneznieto Jul 25, 2023
59fa37c
Add TcpSocket Suite
antoniojimeneznieto Jul 25, 2023
ca46d74
Reformat UringSocket
antoniojimeneznieto Jul 25, 2023
ff89a44
Add SockaddrIn
antoniojimeneznieto Jul 25, 2023
dd1f553
Move createBuffer to util
antoniojimeneznieto Jul 25, 2023
f8f331b
Add SocketGroup and Implement client and server
antoniojimeneznieto Jul 25, 2023
f19997f
Add DatagramSocketGroup
antoniojimeneznieto Jul 25, 2023
1714e86
Echo test working
antoniojimeneznieto Jul 25, 2023
3abe875
Add bind, listen, accept and apply for LinuxSocket
antoniojimeneznieto Jul 26, 2023
7f739eb
Implement serverResource
antoniojimeneznieto Jul 27, 2023
6b4940a
Add tests for serverResource
antoniojimeneznieto Jul 27, 2023
c738459
Add readIPv4
antoniojimeneznieto Jul 27, 2023
1df8f92
Correct serverResource
antoniojimeneznieto Jul 27, 2023
c9d9fe4
Reserve bit 0 to timeout
antoniojimeneznieto Jul 27, 2023
fe438f7
Increase timeout for testing
antoniojimeneznieto Jul 27, 2023
f152bd3
Add simple test
antoniojimeneznieto Jul 27, 2023
9562db6
Add more tests
antoniojimeneznieto Jul 28, 2023
3b7b38c
Formatting
antoniojimeneznieto Jul 28, 2023
059ff22
Isolate server bug in tests
antoniojimeneznieto Jul 28, 2023
5443096
Add prints in server
antoniojimeneznieto Jul 29, 2023
23205a8
Review server
antoniojimeneznieto Jul 29, 2023
4f522f0
Fix server bug
antoniojimeneznieto Jul 30, 2023
393c98c
Add test for server
antoniojimeneznieto Jul 30, 2023
79ebcf7
Add comments and TODO
antoniojimeneznieto Jul 30, 2023
a2e14ef
Remove rwFlags in OP_ACCEPT
antoniojimeneznieto Jul 31, 2023
d0b673b
Add prints in Poll
antoniojimeneznieto Jul 31, 2023
20b3ff2
Add ringFd on prints
antoniojimeneznieto Jul 31, 2023
a342b06
Add ringFd in enqueue
antoniojimeneznieto Jul 31, 2023
1b468d9
Remove TODO
antoniojimeneznieto Jul 31, 2023
5ee436f
Add uringOpenSocket
antoniojimeneznieto Jul 31, 2023
110958d
Correct domain
antoniojimeneznieto Jul 31, 2023
4422d87
Replace Mutex with Semaphore in Native
antoniojimeneznieto Aug 6, 2023
8273561
Add DatagramSocket
antoniojimeneznieto Aug 6, 2023
7f2d0ba
Format UringSocket
antoniojimeneznieto Aug 6, 2023
c8fccc3
Add address length
antoniojimeneznieto Aug 7, 2023
776f411
Rewrite client and server using for-comprehension
antoniojimeneznieto Aug 7, 2023
3561b51
Refactor client and serverResource
antoniojimeneznieto Aug 7, 2023
a322a73
Wrap write in buffer
antoniojimeneznieto Aug 7, 2023
801cb40
add TODO
antoniojimeneznieto Aug 7, 2023
cfd82f4
Wrap bufLength write capacity in a Resource[F,A]
antoniojimeneznieto Aug 8, 2023
bdf2268
Remove print bytes
antoniojimeneznieto Aug 8, 2023
0659f5b
Correct bug and rewrite using for-comprehension
antoniojimeneznieto Aug 8, 2023
6659989
Add replicateA to tests
antoniojimeneznieto Aug 8, 2023
7e057db
Add better prints for debugging
antoniojimeneznieto Aug 8, 2023
053cb86
Add logger for cats effect
antoniojimeneznieto Aug 8, 2023
40bc403
Add logger for cats effect
antoniojimeneznieto Aug 8, 2023
30c1e5f
Revert "Add logger for cats effect"
antoniojimeneznieto Aug 8, 2023
ce99d4d
Revert "Revert "Add logger for cats effect""
antoniojimeneznieto Aug 8, 2023
89cac94
Remove logger
antoniojimeneznieto Aug 8, 2023
b3e83b2
Add pipe for testing
antoniojimeneznieto Aug 9, 2023
95eacc8
Add prints for debugging interrupt
antoniojimeneznieto Aug 9, 2023
80a39a9
Simplify Poll
antoniojimeneznieto Aug 11, 2023
b8433bb
Add print in submission test
antoniojimeneznieto Aug 11, 2023
1d9bfaf
Add JNA
antoniojimeneznieto Aug 11, 2023
6df58b5
Create Pipe class
antoniojimeneznieto Aug 11, 2023
0789124
Add prints for cancel
antoniojimeneznieto Aug 11, 2023
730ad95
Debug PollingSystem with one thread
antoniojimeneznieto Aug 13, 2023
51367ce
Sketch interrupt using FileDescriptor
antoniojimeneznieto Aug 13, 2023
1967536
Handle interrupt
antoniojimeneznieto Aug 14, 2023
1a32946
Poll handles correctly UringSystemSuite
antoniojimeneznieto Aug 15, 2023
e91ab6f
Debug poll and TcpSocketSuite work
antoniojimeneznieto Aug 15, 2023
5f6c476
Add concurrent Map to track op and poller
antoniojimeneznieto Aug 16, 2023
190d060
Add TODO for handling cancellation on the right poller
antoniojimeneznieto Aug 16, 2023
e01b2a3
Abstract operations parameters in a class
antoniojimeneznieto Aug 18, 2023
6ae4b33
Handle cancellation from a different thread
antoniojimeneznieto Aug 18, 2023
9f81ecd
Wake up the canceled ring from the current ring
antoniojimeneznieto Aug 18, 2023
8b80653
Add TODO with bugs to correct in tests
antoniojimeneznieto Aug 18, 2023
be666a3
Add poller fd in prints
antoniojimeneznieto Aug 18, 2023
0556843
Fix bug related to timeout
antoniojimeneznieto Aug 21, 2023
92ce059
Remove operation
antoniojimeneznieto Aug 21, 2023
ae0c8fa
Remove pipe
antoniojimeneznieto Aug 21, 2023
5f40156
Remove JNA
antoniojimeneznieto Aug 21, 2023
4186384
Remove unnecessary import
antoniojimeneznieto Aug 22, 2023
edbac06
Fix timeout bug
antoniojimeneznieto Aug 22, 2023
a6dcf88
Comment unused import
antoniojimeneznieto Aug 22, 2023
be86490
Add comment
antoniojimeneznieto Aug 22, 2023
2430e9e
Remove todo
antoniojimeneznieto Aug 22, 2023
54852f8
Add debug
antoniojimeneznieto Aug 22, 2023
121d030
Add debug
antoniojimeneznieto Aug 22, 2023
f482e39
Remove invalid test for JVM version
antoniojimeneznieto Aug 22, 2023
99ababa
Wrap buffer write in Resource
antoniojimeneznieto Aug 22, 2023
7a25084
Update todo
antoniojimeneznieto Aug 22, 2023
e6da2a7
Remove temporarily DatagramSocket
antoniojimeneznieto Aug 22, 2023
8a20450
Add header and remove unused import
antoniojimeneznieto Aug 22, 2023
4f55885
formatting
antoniojimeneznieto Aug 22, 2023
048722d
Fix naming error: double definition
antoniojimeneznieto Aug 22, 2023
ef64368
Update native folder
antoniojimeneznieto Aug 22, 2023
d43e280
Add more common errors
antoniojimeneznieto Aug 22, 2023
1293817
Update workflow to find the new native directory
antoniojimeneznieto Aug 22, 2023
9876348
add documentation
antoniojimeneznieto Aug 22, 2023
e98acdd
postman echo was moved
antoniojimeneznieto Aug 22, 2023
3028ac0
Remove errors log
antoniojimeneznieto Aug 23, 2023
664b428
It wasn't moved permanetly
antoniojimeneznieto Aug 23, 2023
56e8673
Add read test with remote disconnection
antoniojimeneznieto Aug 23, 2023
17166af
Correct error -107 (shutdown a disconnected socket)
antoniojimeneznieto Aug 25, 2023
bb1b3db
Add mask
antoniojimeneznieto Aug 25, 2023
94d6a23
Add Error
antoniojimeneznieto Aug 25, 2023
26ea3d5
Mask error ENOTCONN when Shutdown
antoniojimeneznieto Aug 25, 2023
83c39f0
Remove unused parameter
antoniojimeneznieto Aug 25, 2023
1dd1e52
Add mask in Native version
antoniojimeneznieto Aug 25, 2023
e76b9b2
add mask to shutdown when socket has been disconnected
antoniojimeneznieto Aug 25, 2023
5e095ac
formatting
antoniojimeneznieto Aug 25, 2023
85cc34f
Test ignore ENOTCONN when shutdown using masking feature
antoniojimeneznieto Aug 25, 2023
58f4783
Negate rtn value
antoniojimeneznieto Aug 25, 2023
f391a26
Cache default mask
antoniojimeneznieto Aug 25, 2023
a59e5d0
Remove unnecessary interrupt and handleCallback
antoniojimeneznieto Aug 26, 2023
892b94e
Move listening and cancelOperation to a specific function
antoniojimeneznieto Aug 26, 2023
7ed808a
Make Poller extends AbstractSelector
antoniojimeneznieto Aug 28, 2023
4506020
organize code and put end in finally block
antoniojimeneznieto Aug 28, 2023
198a4a0
Merge remote-tracking branch 'upstream/feature/jvm' into feature/jvm
armanbilge Aug 28, 2023
af9488d
Fixups
armanbilge Aug 28, 2023
4e332b9
Fixup
armanbilge Aug 28, 2023
b655bb4
Fix netty deps
armanbilge Aug 28, 2023
dfbef6b
Add timeout test
antoniojimeneznieto Aug 28, 2023
51d90f8
Fixups
armanbilge Aug 28, 2023
d9b481b
Update netty version
antoniojimeneznieto Sep 1, 2023
fba3875
Add warmup for timeout test
antoniojimeneznieto Sep 1, 2023
cea2b12
Use send_msg for interruption and sketch getCurrentPollerIfAvailable
antoniojimeneznieto Sep 1, 2023
c8678d7
fix discarded non-Unit error
antoniojimeneznieto Sep 1, 2023
5f9922c
Remove datagramsocket
antoniojimeneznieto Sep 20, 2023
7afdf02
Share App, implicits and ExceptionHelper
antoniojimeneznieto Sep 21, 2023
b4cb557
Share UringSuite and TcpSocketSuite
antoniojimeneznieto Sep 22, 2023
53f32de
formatting
antoniojimeneznieto Sep 22, 2023
6342f80
undo shared in build
antoniojimeneznieto Sep 22, 2023
3471231
formatting
antoniojimeneznieto Sep 22, 2023
a61f589
Update uring/jvm/src/main/scala/fs2/io/uring/unsafe/util.scala
antoniojimeneznieto Sep 23, 2023
b8ee8d3
Open sockets using uring
antoniojimeneznieto Sep 23, 2023
58e628f
Fix buffer release bug
antoniojimeneznieto Sep 23, 2023
fc7f1a4
Change masking error to negative
antoniojimeneznieto Sep 23, 2023
21b2af7
Use resizable buffer for reading and wriing
antoniojimeneznieto Sep 23, 2023
b678106
Replace buffer size with a constant value
antoniojimeneznieto Sep 30, 2023
eee6522
Rename register to access
antoniojimeneznieto Sep 30, 2023
32a3282
Rename register to access
antoniojimeneznieto Sep 30, 2023
b5cfd0b
Add license
antoniojimeneznieto May 1, 2024
6880b0c
Mock Cheshire API
antoniojimeneznieto Aug 4, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,14 @@ ThisBuild / githubWorkflowPublishPreamble +=

val ceVersion = "3.6-e9aeb8c"
val fs2Version = "3.8.0"
val nettyVersion = "0.0.22.Final"
val munitCEVersion = "2.0.0-M3"

lazy val classifier = System.getProperty("os.arch") match {
case "amd64" => "linux-x86_64"
case "aarch64" => "linux-aarch_64"
}

ThisBuild / nativeConfig ~= { c =>
if (Option(System.getenv("CI")).contains("true"))
c.withLinkingOptions(c.linkingOptions :+ "-luring")
Expand All @@ -57,3 +63,11 @@ lazy val uring = crossProject(NativePlatform, JVMPlatform)
),
Test / testOptions += Tests.Argument("+l")
)
.jvmSettings(
libraryDependencies ++= Seq(
"io.netty.incubator" % "netty-incubator-transport-classes-io_uring" % nettyVersion,
("io.netty.incubator" % "netty-incubator-transport-native-io_uring" % nettyVersion % Test)
.classifier(classifier)
),
fork := true
)
76 changes: 76 additions & 0 deletions uring/jvm/src/main/scala/fs2/io/uring/IOExceptionHelper.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
/*
* Copyright 2022 Arman Bilge

Choose a reason for hiding this comment

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

We should probably update the copyright. :-)

Copy link
Owner

Choose a reason for hiding this comment

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

its minez 😏

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

😂

*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package fs2.io.uring

import java.io.IOException
import java.net.ConnectException
import java.net.BindException
import java.net.SocketException
import java.net.SocketTimeoutException
import java.net.NoRouteToHostException

private[uring] object IOExceptionHelper {

def apply(errno: Int): IOException = errno match {
case 9 => // EBADF
new IOException("Bad file descriptor")

case 11 => // EAGAIN
new IOException("Resource temporarily unavailable")

case 13 => // EACCES
new IOException("Permission denied")

case 14 => // EFAULT
new IOException("Bad address")

case 22 => // EINVAL
new IOException("Invalid argument")

case 24 => // EMFILE
new IOException("Too many open files")

case 28 => // ENOSPC
new IOException("No space left on device")

case 32 => // EPIPE
new IOException("Broken pipe")

case 98 => // EADDRINUSE
new BindException("Address already in use")

case 99 => // EADDRNOTAVAIL
new BindException("Cannot assign requested address")

case 107 => // ECONNABORTED
new SocketException("Connection aborted")

case 110 => // ETIMEDOUT
new SocketTimeoutException("Connection timed out")

case 111 => // ECONNREFUSED
new ConnectException("Connection refused")

case 113 => // EHOSTUNREACH
new NoRouteToHostException("No route to host")

case 104 => // ECONNRESET
new SocketException("Connection reset by peer")

case _ => new IOException(errno.toString)
}
}
59 changes: 59 additions & 0 deletions uring/jvm/src/main/scala/fs2/io/uring/Uring.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
/*
* Copyright 2022 Arman Bilge
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package fs2.io.uring

import cats.effect.IO
import cats.effect.LiftIO
import cats.effect.kernel.Resource
import cats.syntax.all._

abstract class Uring private[uring] {
private[this] val noopMask: Int => Boolean = _ => false

def call(
op: Byte,
flags: Int = 0,
rwFlags: Int = 0,
fd: Int = 0,
bufferAddress: Long = 0,
length: Int = 0,
offset: Long = 0,
mask: Int => Boolean = noopMask
): IO[Int]

def bracket(
op: Byte,
flags: Int = 0,
rwFlags: Int = 0,
fd: Int = 0,
bufferAddress: Long = 0,
length: Int = 0,
offset: Long = 0,
mask: Int => Boolean = noopMask
)(release: Int => IO[Unit]): Resource[IO, Int]
}

object Uring {

def get[F[_]: LiftIO]: F[Uring] =
IO.pollers.flatMap {
_.collectFirst { case ring: Uring =>
ring
}.liftTo[IO](new RuntimeException("No UringSystem installed"))
}.to

}
30 changes: 30 additions & 0 deletions uring/jvm/src/main/scala/fs2/io/uring/UringApp.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
/*
* Copyright 2022 Arman Bilge
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package fs2.io.uring

import cats.effect.IOApp
import fs2.io.uring.unsafe.UringSystem

trait UringApp extends IOApp {

override protected final def pollingSystem = UringSystem

}

object UringApp {
trait Simple extends IOApp.Simple with UringApp
}
28 changes: 28 additions & 0 deletions uring/jvm/src/main/scala/fs2/io/uring/implicits.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
/*
* Copyright 2022 Arman Bilge
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package fs2.io.uring

import cats.effect.LiftIO
import cats.effect.kernel.Async
import com.comcast.ip4s.Dns
import fs2.io.net.Network

object implicits {

@inline implicit def network[F[_]: Async: Dns: LiftIO]: Network[F] = ???

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
/*
* Copyright 2022 Arman Bilge
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package fs2.io.uring.net

import cats.effect.kernel.Resource

import com.comcast.ip4s._

import fs2.io.net.DatagramSocketGroup
import fs2.io.net.DatagramSocket
import fs2.io.net._

import java.net.ProtocolFamily

private final class UringDatagramSocketGroup[F[_]] extends DatagramSocketGroup[F] {
Copy link
Owner

Choose a reason for hiding this comment

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

I guess we can work on this in a follow-up PR :)

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

If you don't mind one last request: can we make an effort to deduplicate some of code and share between JVM/Native?

Great idea! I'll handle it :)

But ... I think we should try hard to share the tests, so we are running identical test suites on both platforms. We're not doing anything JVM-specific, hopefully?

I think we aren't, so it should be easy to do.


override def openDatagramSocket(
address: Option[Host],
port: Option[Port],
options: List[DatagramSocketOption],
protocolFamily: Option[ProtocolFamily]
): Resource[F, DatagramSocket[F]] = ???

}

object UringDatagramSocketGroup {
def apply[F[_]]: DatagramSocketGroup[F] = new UringDatagramSocketGroup
}
87 changes: 87 additions & 0 deletions uring/jvm/src/main/scala/fs2/io/uring/net/UringNetwork.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
/*
* Copyright 2022 Arman Bilge
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package fs2.io.uring.net

import cats.effect.LiftIO
import cats.effect.kernel.Async
import cats.effect.kernel.Resource

import com.comcast.ip4s.Dns
import com.comcast.ip4s.Host
import com.comcast.ip4s.Port
import com.comcast.ip4s.SocketAddress
import com.comcast.ip4s.IpAddress

import fs2.Stream
import fs2.io.net.Network
import fs2.io.net.SocketOption
import fs2.io.net.tls.TLSContext
import fs2.io.net.SocketGroup
import fs2.io.net.Socket
import fs2.io.net.DatagramSocket
import fs2.io.net.DatagramSocketGroup
import fs2.io.net.DatagramSocketOption

import java.net.ProtocolFamily

import java.util.concurrent.ThreadFactory

private[net] final class UringNetwork[F[_]](
sg: UringSocketGroup[F],
dsg: UringDatagramSocketGroup[F],
val tlsContext: TLSContext.Builder[F]
) extends Network.UnsealedNetwork[F] {

def socketGroup(threadCount: Int, threadFactory: ThreadFactory): Resource[F, SocketGroup[F]] =
Resource.pure[F, SocketGroup[F]](sg)

def datagramSocketGroup(threadFactory: ThreadFactory): Resource[F, DatagramSocketGroup[F]] =
Resource.pure[F, DatagramSocketGroup[F]](dsg)

def client(to: SocketAddress[Host], options: List[SocketOption]): Resource[F, Socket[F]] =
sg.client(to, options)

def server(
address: Option[Host],
port: Option[Port],
options: List[SocketOption]
): Stream[F, Socket[F]] = sg.server(address, port, options)

def serverResource(
address: Option[Host],
port: Option[Port],
options: List[SocketOption]
): Resource[F, (SocketAddress[IpAddress], Stream[F, Socket[F]])] =
sg.serverResource(address, port, options)

def openDatagramSocket(
address: Option[Host],
port: Option[Port],
options: List[DatagramSocketOption],
protocolFamily: Option[ProtocolFamily]
): Resource[F, DatagramSocket[F]] =
dsg.openDatagramSocket(address, port, options, protocolFamily)
}

object UringNetwork {
def apply[F[_]: Async: Dns: LiftIO]: Network[F] =
new UringNetwork(
new UringSocketGroup[F],
new UringDatagramSocketGroup[F],
TLSContext.Builder.forAsync[F]
)
}
Loading