public static void CheckStatus(ZitiStatus status) { if (status != ZitiStatus.OK) { throw new ZitiException(status); } }
private static void onConnected(ZitiConnection connection, ZitiStatus status) { ZitiUtil.CheckStatus(status); string cfg = connection.Service.GetConfiguration("weather-config-type"); string where = null; if (cfg == null) { where = "London"; Console.WriteLine("The service does not have a configuration of type 'weather-config-type' - using default: " + where); } else { where = JsonDocument.Parse(cfg).RootElement.GetProperty("where").ToString(); } byte[] bytes = Encoding.UTF8.GetBytes($"GET /{where} HTTP/1.0\r\n" + "Accept: *-/*\r\n" + "Connection: close\r\n" + "User-Agent: curl/7.59.0\r\n" + "Host: wttr.in\r\n" + "\r\n"); connection.Write(bytes, afterDataWritten, "write context"); }
private static void onClientAccept(ZitiConnection clientConnection, ZitiStatus status) { ZitiUtil.CheckStatus(status); string msg = "Hello from byte counter!"; clientConnection.Write(Encoding.UTF8.GetBytes(msg), msg.Length, afterDataWritten, ZitiUtil.NO_CONTEXT); }
private static void listenCallback(ZitiConnection connection, ZitiStatus status) { if (status == ZitiStatus.OK) { Console.WriteLine("Byte Counter is ready! %s", status.GetDescription()); } else { Console.WriteLine("ERROR: The Byte Counter could not be started! " + status.GetDescription()); connection.Close(); Environment.Exit(0); } }
public static void CheckStatus(ZitiStatus status) { if (status.Ok()) { //good. carry on. } else { //something went wrong. inspect the erorr here... Console.WriteLine("An error occurred."); Console.WriteLine(" ZitiStatus : " + status); Console.WriteLine(" : " + status.GetDescription()); } }
public void MarkAsStream() { isStream = true; if (isDialed) { throw new InvalidOperationException("Cannot AsStream on a connection that is already Dialed."); } //assign delegate to a local variable so that it is not elligable for GC ozc = (IntPtr nf_connection, int status) => { lock (this) { if (status < 0) { Logger.Debug("connection not ready for writing: " + status); this.connectionReadyStatus = (ZitiStatus)status; } else { Logger.Debug("marking stream ready for writing"); } Monitor.Pulse(this); this.readyForWriting = true; } }; //assign delegate to a local variable so that it is not elligable for GC ozdr = (IntPtr nf_connection, IntPtr rawData, int len) => { if (len > 0) { //need to copy the memory from c - into managed code and then write into the pipeline buffer //it would be much better to just read from byte[] data = new byte[len]; Logger.Debug("got bytes from ziti: " + len + " responses size: " + responses.Count); Marshal.Copy(rawData, data, 0, len); this.responses.Add(data); return(len); } else { this.responses.CompleteAdding(); return(0); } }; //Ziti.Dial(nf_connection, serviceName, ozc, ozdr); Native.API.ziti_dial(nativeConnection, Service.Name, ozc, ozdr); }
private static void onConnected(ZitiConnection connection, ZitiStatus status) { ZitiUtil.CheckStatus(status); Console.WriteLine("sending HTTP request: " + connection.ConnectionContext); string payload = @"GET / HTTP/1.0 Host: eth0.me User-Agent: curl/7.55.1 Accept: */* "; byte[] bytes = System.Text.Encoding.UTF8.GetBytes(payload); connection.Write(bytes, afterDataWritten, "write context"); }
private static void onData(ZitiConnection connection, ZitiStatus status, byte[] data) { if (status == ZitiStatus.OK) { ms.Write(data); //collect all the bytes to display contiguously at the end of the program } else { if (status == ZitiStatus.EOF) { ConsoleHelper.OutputResponseToConsole(ms.ToArray()); Console.WriteLine("request completed: " + status.GetDescription()); connection.Close(); Environment.Exit(0); } else { Console.WriteLine("unexpected error: " + status.GetDescription()); } ConsoleHelper.OutputResponseToConsole(ms.ToArray()); } }
public static void Check(this ZitiStatus status) { ZitiUtil.CheckStatus(status); }
private static void onServiceChange(ZitiContext zitiContext, ZitiService service, ZitiStatus status, int flags, object serviceContext) { if (service.Name == serviceContext.ToString()) { //start a listener on the socket service.Listen(listenCallback, onClientConnect); } else { Console.WriteLine($"Service {service.Name} is not the service we're looking for..."); } }
public static void CheckStatus(ZitiContext zitiContext, ZitiStatus status, object initContext) { status.Check(); }
private static void onData(ZitiConnection connection, ZitiStatus status, byte[] data) { }
private void afterEnroll(ZitiStatus status) { throw new NotImplementedException(); }
/// <summary> /// The basic constructor for creating a ZitiException /// </summary> /// <param name="message">The message</param> public ZitiException(ZitiStatus status) : base(status.GetDescription()) { }
public static bool Ok(this ZitiStatus s) { return(s == ZitiStatus.OK); }
private static void onClientConnect(ZitiConnection serverConnection, ZitiConnection clientConnection, ZitiStatus status) { Console.WriteLine("Client is connected"); clientConnection.Accept(onClientAccept, onClientData); }
private static void onClientData(ZitiConnection clientConnection, byte[] data, int len, ZitiStatus status) { if (status == ZitiStatus.OK) { string recd = Encoding.UTF8.GetString(data); Console.WriteLine("client sent: " + recd); string reply = "counted bytes: " + recd.Length; clientConnection.Write(Encoding.UTF8.GetBytes(reply), reply.Length, aftterDataWritten, ZitiUtil.NO_CONTEXT); } else { if (status == ZitiStatus.EOF) { Console.WriteLine("request completed: " + status.GetDescription()); } else { Console.WriteLine("unexpected error: " + status.GetDescription()); } clientConnection.Close(); Environment.Exit(0); } }
private static void onConnected(ZitiConnection connection, ZitiStatus status) { connection.Write(Encoding.UTF8.GetBytes("greetings!"), afterDataWritten, "context?"); }
private static void onData(ZitiConnection connection, ZitiStatus status, byte[] data) { Console.WriteLine(Encoding.UTF8.GetString(data)); }
private static void afterDataWritten(ZitiConnection connection, ZitiStatus status, object context) { ZitiUtil.CheckStatus(status); }
private static void afterDataWritten(ZitiConnection connection, ZitiStatus status, object context) { //don't do anything in c# - nothing to free up here Console.WriteLine("data has been written: " + context?.ToString()); }