Ejemplo n.º 1
0
        /// <summary>
        /// Create a new CTX structure
        /// </summary>
        /// <param name="method">method to use such as TLSv1.2</param>
        /// <returns>pointer to CTX structure</returns>
        public static IntPtr CTX_new(IntPtr method)
        {
            try
            {
                IntPtr ctx = wolfSSL_CTX_new(method);
                if (ctx == IntPtr.Zero)
                    return ctx;

                ctx_handles io = new ctx_handles();
                io.set_ctx(ctx);

                CallbackIORecv_delegate recv = new CallbackIORecv_delegate(wolfssl.wolfSSLCbIORecv);
                io.set_receive(GCHandle.Alloc(recv));
                wolfSSL_SetIORecv(ctx, recv);

                CallbackIOSend_delegate send = new CallbackIOSend_delegate(wolfssl.wolfSSLCbIOSend);
                io.set_send(GCHandle.Alloc(send));
                wolfSSL_SetIOSend(ctx, send);

                /* keep memory pinned */
                return GCHandle.ToIntPtr(GCHandle.Alloc(io, GCHandleType.Pinned));
            }
            catch (Exception e)
            {
                log(ERROR_LOG, "ctx_new error " + e.ToString());
                return IntPtr.Zero;
            }
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Optional, can be used to set a custom recieve function
        /// </summary>
        /// <param name="ctx">structure to set recieve function in</param>
        /// <param name="func">function to use when reading socket</param>
        public static void SetIORecv(IntPtr ctx, CallbackIORecv_delegate func)
        {
            try
            {
                GCHandle gch = GCHandle.FromIntPtr(ctx);
                ctx_handles handles = (ctx_handles)gch.Target;

                /* check if already stored handle needs freed */
                gch = handles.get_receive();
                if (!Object.Equals(gch, default(GCHandle)))
                {
                    gch.Free();
                }

                /* keep new function alive */
                handles.set_receive(GCHandle.Alloc(func));

                wolfSSL_SetIORecv(handles.get_ctx(), func);
            }
            catch (Exception e)
            {
                log(ERROR_LOG, "wolfssl setIORecv error " + e.ToString());
            }
        }
Ejemplo n.º 3
0
 private static extern int wolfSSL_SetIORecv(IntPtr ctx, CallbackIORecv_delegate recv);