public PortComHandle AcceptConnect(PortMessage message, bool accept) { NtStatus status; IntPtr portHandle; using (var messageMemory = message.ToMemory()) { if ((status = Win32.NtAcceptConnectPort( out portHandle, IntPtr.Zero, messageMemory, accept, IntPtr.Zero, IntPtr.Zero )) >= NtStatus.Error) { Win32.Throw(status); } if (!NativeHandle.IsInvalid(portHandle)) { return(new PortComHandle(portHandle, true)); } else { return(null); } } }
public void Reply(PortMessage message) { using (MemoryAlloc messageMemory = message.ToMemory()) { Win32.NtReplyPort(this, messageMemory).ThrowIf(); message.SetHeader(messageMemory); } }
public PortMessage Listen() { using (MemoryAlloc buffer = PortMessage.AllocateBuffer()) { Win32.NtListenPort(this, buffer).ThrowIf(); return(new PortMessage(buffer)); } }
//获得请求车把复位命令 public static byte[] GetRequestReset() { PortMessage pm = new PortMessage(); pm.cmd = CmdRequestReset; pm.len = 0x01; pm.data = new int[] { 0x00 }; pm.checksum = (pm.cmd + pm.len + 0x00) & 0xFF; return(pm.GetBytes()); }
public const int ClearDataID = 0x01; //清除运动资料 //获得请求清空数据命令 public static byte[] GetRequestCtr(int resistanceForce, int cmd) { PortMessage pm = new PortMessage(); pm.cmd = CmdResuestCtr; pm.len = 0x02; pm.data = new int[] { resistanceForce, cmd }; pm.checksum = (pm.cmd + pm.len + resistanceForce + cmd) & 0xFF; return(pm.GetBytes()); }
public PortMessage ReplyWaitReply(PortMessage message) { using (MemoryAlloc messageMemory = message.ToMemory()) { Win32.NtReplyWaitReplyPort( this, messageMemory ).ThrowIf(); return(new PortMessage(messageMemory)); } }
public void Reply(PortMessage message) { NtStatus status; using (var messageMemory = message.ToMemory()) { if ((status = Win32.NtReplyPort(this, messageMemory)) >= NtStatus.Error) { Win32.ThrowLastError(status); } message.SetHeader(messageMemory); } }
public PortMessage Listen() { NtStatus status; using (var buffer = PortMessage.AllocateBuffer()) { if ((status = Win32.NtListenPort(this, buffer)) >= NtStatus.Error) { Win32.Throw(status); } return(new PortMessage(buffer)); } }
public PortMessage RequestWaitReply(PortMessage message) { using (MemoryAlloc buffer = PortMessage.AllocateBuffer()) using (MemoryAlloc messageMemory = message.ToMemory()) { Win32.NtRequestWaitReplyPort( this, messageMemory, buffer ).ThrowIf(); message.SetHeader(messageMemory); return(new PortMessage(buffer)); } }
public PortMessage ReplyWaitReply(PortMessage message) { NtStatus status; using (var messageMemory = message.ToMemory()) { if ((status = Win32.NtReplyWaitReplyPort( this, messageMemory )) >= NtStatus.Error) { Win32.ThrowLastError(status); } return(new PortMessage(messageMemory)); } }
public PortMessage ReplyWaitReceive(PortMessage message) { NtStatus status; IntPtr context; using (var buffer = PortMessage.AllocateBuffer()) { MemoryAlloc messageMemory = null; if (message != null) { messageMemory = message.ToMemory(); } try { if ((status = Win32.NtReplyWaitReceivePort( this, out context, messageMemory ?? IntPtr.Zero, buffer )) >= NtStatus.Error) { Win32.ThrowLastError(status); } if (message != null) { message.SetHeader(messageMemory); } } finally { if (messageMemory != null) { messageMemory.Dispose(); } } return(new PortMessage(buffer)); } }
public PortMessage RequestWaitReply(PortMessage message) { NtStatus status; using (var buffer = PortMessage.AllocateBuffer()) using (var messageMemory = message.ToMemory()) { if ((status = Win32.NtRequestWaitReplyPort( this, messageMemory, buffer )) >= NtStatus.Error) { Win32.ThrowLastError(status); } message.SetHeader(messageMemory); return(new PortMessage(buffer)); } }
public void PortMessage_TryDecode() { PortMessage message; int offset = 0; bool isIncomplete; byte[] data = "00000003090FAC".ToByteArray(); if (PortMessage.TryDecode(data, ref offset, data.Length, out message, out isIncomplete)) { Assert.AreEqual(7, message.Length); Assert.AreEqual(4012, message.Port); Assert.AreEqual(false, isIncomplete); Assert.AreEqual(data.Length, offset); CollectionAssert.AreEqual(data, message.Encode()); } else { Assert.Fail(); } }
public PortMessage ReplyWaitReceive(PortMessage message) { using (MemoryAlloc buffer = PortMessage.AllocateBuffer()) { MemoryAlloc messageMemory = null; if (message != null) { messageMemory = message.ToMemory(); } try { IntPtr context; Win32.NtReplyWaitReceivePort( this, out context, messageMemory ?? IntPtr.Zero, buffer ).ThrowIf(); if (message != null) { message.SetHeader(messageMemory); } } finally { if (messageMemory != null) { messageMemory.Dispose(); } } return(new PortMessage(buffer)); } }
public PortComHandle AcceptConnect(PortMessage message, bool accept) { IntPtr portHandle; using (MemoryAlloc messageMemory = message.ToMemory()) { Win32.NtAcceptConnectPort( out portHandle, IntPtr.Zero, messageMemory, accept, IntPtr.Zero, IntPtr.Zero ).ThrowIf(); if (!NativeHandle.IsInvalid(portHandle)) { return(new PortComHandle(portHandle, true)); } return(null); } }
/// <summary> /// Send port message asynchronously /// </summary> /// <param name="port">the listenning port of dht</param> public void SendPortMessageAsync(ushort port) { PortMessage message = new PortMessage(port); SendMessageAsync(message); }
protected virtual void HandlePortMessage(PeerId id, PortMessage message) { id.Port = message.Port; }
public void PortEncoding() { int length = new PortMessage(2500).Encode(buffer, offset); Assert.AreEqual("00-00-00-03-09-09-C4", BitConverter.ToString(buffer, offset, length)); }
protected virtual void HandlePortMessage(PeerId id, PortMessage message) { id.Port = (ushort)message.Port; }
void peer_PortMessageReceived(object sender, PortMessage e) { ShowMessage("{0}:Received {1}", sender, e); }
public override bool Equals(object obj) { PortMessage msg = obj as PortMessage; return((msg == null) ? false : (this.port == msg.port)); }