Skip to content

Commit

Permalink
Debugging changes. Updated xcode build schemes.
Browse files Browse the repository at this point in the history
  • Loading branch information
Tylerian committed Aug 13, 2018
1 parent b5c7e67 commit 9e0faea
Show file tree
Hide file tree
Showing 10 changed files with 157 additions and 20 deletions.
3 changes: 3 additions & 0 deletions C/Sources/fs_byte_buffer_init.c
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,9 @@ int fs_byte_buffer_init(fs_byte_buffer_t* buffer, uint32_t capacity)
buffer->heap[i] = 0;
}*/

/* Set capacity */
buffer->capacity = capacity;

/* Set marks to zero */
buffer->reader_mark = 0;
buffer->writer_mark = 0;
Expand Down
8 changes: 1 addition & 7 deletions Fuse.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,6 @@
57477A6320B30061007BC236 /* fs_byte_buffer_write_int64.c in Sources */ = {isa = PBXBuildFile; fileRef = 5786943D20B04E71001F3DC6 /* fs_byte_buffer_write_int64.c */; };
57477A6420B30061007BC236 /* fs_byte_buffer_write_bytes.c in Sources */ = {isa = PBXBuildFile; fileRef = 5786947820B180EB001F3DC6 /* fs_byte_buffer_write_bytes.c */; };
57867BF720B575840004456A /* fs_byte_buffer_resize.c in Sources */ = {isa = PBXBuildFile; fileRef = 57867BF620B575840004456A /* fs_byte_buffer_resize.c */; };
57867C0920BC25080004456A /* Info.plist in Resources */ = {isa = PBXBuildFile; fileRef = 5786941520AF675E001F3DC6 /* Info.plist */; };
57867C7B20BF5E340004456A /* Fuse.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 5786941120AF675E001F3DC6 /* Fuse.framework */; };
57867C8120BF5E440004456A /* ChannelTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 57867C7020BF5DCB0004456A /* ChannelTests.swift */; };
57867C8320C1EFCF0004456A /* ByteBufTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 57867C8220C1EFCF0004456A /* ByteBufTests.swift */; };
Expand All @@ -63,7 +62,6 @@
57867CAB20C8970B0004456A /* ByteBuffer.swift in Sources */ = {isa = PBXBuildFile; fileRef = 57867CAA20C8970B0004456A /* ByteBuffer.swift */; };
57867CAD20C897840004456A /* Endianness.swift in Sources */ = {isa = PBXBuildFile; fileRef = 57867CAC20C897840004456A /* Endianness.swift */; };
57867CB120C9654C0004456A /* fs_byte_buffer_resize.c in Sources */ = {isa = PBXBuildFile; fileRef = 57867BF620B575840004456A /* fs_byte_buffer_resize.c */; };
57867CB220CA0CB10004456A /* Info.plist in Resources */ = {isa = PBXBuildFile; fileRef = 57867C7A20BF5E340004456A /* Info.plist */; };
5786941620AF675E001F3DC6 /* Fuse.h in Headers */ = {isa = PBXBuildFile; fileRef = 5786941420AF675E001F3DC6 /* Fuse.h */; settings = {ATTRIBUTES = (Public, ); }; };
5786949C20B19398001F3DC6 /* fuse_private.h in Headers */ = {isa = PBXBuildFile; fileRef = 5786942B20B04C39001F3DC6 /* fuse_private.h */; settings = {ATTRIBUTES = (Private, ); }; };
5786949D20B1939E001F3DC6 /* fuse.h in Headers */ = {isa = PBXBuildFile; fileRef = 5786942120B01ED4001F3DC6 /* fuse.h */; settings = {ATTRIBUTES = (Public, ); }; };
Expand Down Expand Up @@ -450,7 +448,7 @@
isa = PBXProject;
attributes = {
LastSwiftUpdateCheck = 0930;
LastUpgradeCheck = 0930;
LastUpgradeCheck = 0940;
ORGANIZATIONNAME = Tylerian;
TargetAttributes = {
57867C7520BF5E340004456A = {
Expand Down Expand Up @@ -494,15 +492,13 @@
isa = PBXResourcesBuildPhase;
buildActionMask = 2147483647;
files = (
57867CB220CA0CB10004456A /* Info.plist in Resources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
5786940F20AF675E001F3DC6 /* Resources */ = {
isa = PBXResourcesBuildPhase;
buildActionMask = 2147483647;
files = (
57867C0920BC25080004456A /* Info.plist in Resources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
Expand Down Expand Up @@ -716,7 +712,6 @@
GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE;
GCC_WARN_UNUSED_FUNCTION = YES;
GCC_WARN_UNUSED_VARIABLE = YES;
IPHONEOS_DEPLOYMENT_TARGET = 11.3;
MTL_ENABLE_DEBUG_INFO = YES;
ONLY_ACTIVE_ARCH = YES;
SDKROOT = iphoneos;
Expand Down Expand Up @@ -773,7 +768,6 @@
GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE;
GCC_WARN_UNUSED_FUNCTION = YES;
GCC_WARN_UNUSED_VARIABLE = YES;
IPHONEOS_DEPLOYMENT_TARGET = 11.3;
MTL_ENABLE_DEBUG_INFO = NO;
SDKROOT = iphoneos;
SWIFT_COMPILATION_MODE = wholemodule;
Expand Down
2 changes: 1 addition & 1 deletion Fuse.xcodeproj/xcshareddata/xcschemes/CFuse.xcscheme
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<Scheme
LastUpgradeVersion = "0930"
LastUpgradeVersion = "0940"
version = "1.3">
<BuildAction
parallelizeBuildables = "YES"
Expand Down
80 changes: 80 additions & 0 deletions Fuse.xcodeproj/xcshareddata/xcschemes/Fuse.xcscheme
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
<?xml version="1.0" encoding="UTF-8"?>
<Scheme
LastUpgradeVersion = "0940"
version = "1.3">
<BuildAction
parallelizeBuildables = "YES"
buildImplicitDependencies = "YES">
<BuildActionEntries>
<BuildActionEntry
buildForTesting = "YES"
buildForRunning = "YES"
buildForProfiling = "YES"
buildForArchiving = "YES"
buildForAnalyzing = "YES">
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "5786941020AF675E001F3DC6"
BuildableName = "Fuse.framework"
BlueprintName = "Fuse"
ReferencedContainer = "container:Fuse.xcodeproj">
</BuildableReference>
</BuildActionEntry>
</BuildActionEntries>
</BuildAction>
<TestAction
buildConfiguration = "Debug"
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
shouldUseLaunchSchemeArgsEnv = "YES">
<Testables>
</Testables>
<AdditionalOptions>
</AdditionalOptions>
</TestAction>
<LaunchAction
buildConfiguration = "Debug"
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
launchStyle = "0"
useCustomWorkingDirectory = "NO"
ignoresPersistentStateOnLaunch = "NO"
debugDocumentVersioning = "YES"
debugServiceExtension = "internal"
allowLocationSimulation = "YES">
<MacroExpansion>
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "5786941020AF675E001F3DC6"
BuildableName = "Fuse.framework"
BlueprintName = "Fuse"
ReferencedContainer = "container:Fuse.xcodeproj">
</BuildableReference>
</MacroExpansion>
<AdditionalOptions>
</AdditionalOptions>
</LaunchAction>
<ProfileAction
buildConfiguration = "Release"
shouldUseLaunchSchemeArgsEnv = "YES"
savedToolIdentifier = ""
useCustomWorkingDirectory = "NO"
debugDocumentVersioning = "YES">
<MacroExpansion>
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "5786941020AF675E001F3DC6"
BuildableName = "Fuse.framework"
BlueprintName = "Fuse"
ReferencedContainer = "container:Fuse.xcodeproj">
</BuildableReference>
</MacroExpansion>
</ProfileAction>
<AnalyzeAction
buildConfiguration = "Debug">
</AnalyzeAction>
<ArchiveAction
buildConfiguration = "Release"
revealArchiveInOrganizer = "YES">
</ArchiveAction>
</Scheme>
2 changes: 1 addition & 1 deletion Fuse.xcodeproj/xcshareddata/xcschemes/FuseTests.xcscheme
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<Scheme
LastUpgradeVersion = "0930"
LastUpgradeVersion = "0940"
version = "2.0">
<BuildAction
parallelizeBuildables = "YES"
Expand Down
1 change: 1 addition & 0 deletions Swift/Sources/Buffers/ByteBuffer.swift
Original file line number Diff line number Diff line change
Expand Up @@ -486,6 +486,7 @@ extension UnsafeByteBuffer: ByteBufferWritable {
}

public func write(bytes value: [UInt8]) -> Self {
print("Writing bytes: \(value) -- \(value.count)")
let result = fs_byte_buffer_write_bytes(&self.handle, UInt32(value.count), value)

guard result == FS_OKAY else {
Expand Down
16 changes: 10 additions & 6 deletions Swift/Sources/Channels/Channel.swift
Original file line number Diff line number Diff line change
@@ -1,32 +1,34 @@
import Foundation

typealias SocketFactory = (Channel) -> Socket

public final class Channel {
private var _socket: Socket!
private var _pipeline: ChannelPipeline!

internal init(socket factory: (Channel) -> Socket) {
internal init(socket factory: SocketFactory) {
self._pipeline = ChannelPipeline(channel: self)
self._socket = factory(self)
}
}

extension Channel {
public var pipeline: ChannelPipeline {
return self._pipeline
internal var socket: Socket {
return self._socket
}
}

extension Channel {
internal var socket: Socket {
return self._socket
public var pipeline: ChannelPipeline {
return self._pipeline
}
}

extension Channel {
public func close() {
self.pipeline.close()
}

public func write(_ data: Any) -> Channel {
self.pipeline.write(data)
return self
Expand Down Expand Up @@ -54,6 +56,8 @@ extension Channel: SocketDelegate {
internal protocol Socket: class {
var delegate: SocketDelegate? { get set }

init(queue: DispatchQueue)

func close() throws
func connect(to host: String, port: Int) throws

Expand Down
7 changes: 2 additions & 5 deletions Swift/Sources/Channels/ChannelHandlerContext.swift
Original file line number Diff line number Diff line change
Expand Up @@ -86,24 +86,20 @@ extension ChannelHandlerContext: InboundChannelHandlerInvoker {
extension ChannelHandlerContext {
private func triggerChannelActive() {
let cast = self._handler as? InboundChannelHandler
print ("triggering channelActive event in context #\(self.name)")

guard let handler = cast else {
self.fireChannelActive()
return
}

print ("triggering channelActive event 1")
self.executor.async(flags: .barrier) { [weak self] in
guard let ctx = self else {
return
}
print ("triggering channelActive event 2")

do {
print ("triggering channelActive event 3")
try handler.channel(active: ctx)
} catch let error {
print ("triggering channelActive event 4")
ctx.triggerError(error)
}
}
Expand Down Expand Up @@ -184,6 +180,7 @@ extension ChannelHandlerContext: OutboundChannelHandlerInvoker {
}

public func write(_ data: Any) {
print("Triggerin write on #\(_prev?.name)")
self._prev?.triggerWrite(data)
}
}
Expand Down
1 change: 1 addition & 0 deletions Swift/Sources/Channels/ChannelPipeline.swift
Original file line number Diff line number Diff line change
Expand Up @@ -279,6 +279,7 @@ fileprivate final class HeadChannelHandler: OutboundChannelHandler {
}

func channel(_ context: ChannelHandlerContext, write data: Any) throws {
print("Writing to underlying socket impl!")
try context.channel.socket.write(data: data)
}
}
Expand Down
57 changes: 57 additions & 0 deletions Swift/Tests/ChannelHandlerTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,61 @@
// Copyright © 2018 Tylerian. All rights reserved.
//

import XCTest
import Foundation
@testable import Fuse

class ChannelHandlerTests: XCTestCase {
var testRunning = true

func testChannelWrite() {
let channel = Channel(socket: { channel in
let socket = TCPSocket(queue: channel.pipeline.executor)
socket.delegate = channel
return socket
})

try! channel.pipeline.add(handler: self, named: "xctest_handler")

channel.pipeline.connect(to: "163.172.34.118", port: 20212)

repeat { Thread.sleep(forTimeInterval: 0.25) } while testRunning
}
}

extension ChannelHandlerTests: DuplexChannelHandler {
func handler(added context: ChannelHandlerContext) throws {
print("[XCTEST] -- Handler added!")
}

func handler(_ context: ChannelHandlerContext, error: Error) throws {
print("[XCTEST] -- Error caught. \(String(describing: error))")
}

func channel(active context: ChannelHandlerContext) throws {
print("[XCTEST] -- Channel active!")
context.fireChannelActive()

var data: ByteBuffer = UnsafeByteBuffer(capacity: 10)
_ = data.write(int32: 5, endianness: .bigEndian)
_ = data.write(bytes: [0xb1, 0xde, 0xb3, 0xb2, 0xb0])

context.write(data)
}

func channel(inactive context: ChannelHandlerContext) throws {
print("[XCTEST] -- Channel inactive!")
context.fireChannelInactive()
testRunning = false
}

func channel(_ context: ChannelHandlerContext, read data: Any) throws {
print("[XCTEST] -- Channel read! -> \(data)")
context.fireChannelRead(data)
}

func channel(_ context: ChannelHandlerContext, write data: Any) throws {
print("[XCTEST] -- Channel write! -> \(data)")
context.write(data)
}
}

0 comments on commit 9e0faea

Please sign in to comment.