// called by libcurlshim private static int ReadDelegate(IntPtr buf, int sz, int nmemb, IntPtr parm) { int bytes = sz * nmemb; byte[] b = new byte[bytes]; GCHandle gch = (GCHandle)parm; Easy easy = (Easy)gch.Target; if (easy == null) { return(0); } if (easy.m_pfRead == null) { return(0); } int nRead = easy.m_pfRead(b, sz, nmemb, easy.m_readData); if (nRead > 0) { for (int i = 0; i < nRead; i++) { Marshal.WriteByte(buf, i, b[i]); } } return(nRead); }
/// <summary> /// Remove an Easy object. /// </summary> /// <param name="easy"> /// <see cref="Easy"/> object to remove. /// </param> /// <returns> /// A <see cref="CURLMcode"/>, hopefully <c>CURLMcode.CURLM_OK</c> /// </returns> /// <exception cref="System.NullReferenceException"> /// This is thrown if the native <c>Multi</c> handle wasn't /// created successfully. /// </exception> public CURLMcode RemoveHandle(Easy easy) { EnsureHandle(); IntPtr p = easy.GetHandle(); m_htEasy.Remove(p); return(External.curl_multi_remove_handle(m_pMulti, easy.GetHandle())); }
/// <summary> /// Add an Easy object. /// </summary> /// <param name="easy"> /// <see cref="Easy"/> object to add. /// </param> /// <returns> /// A <see cref="CURLMcode"/>, hopefully <c>CURLMcode.CURLM_OK</c> /// </returns> /// <exception cref="System.NullReferenceException"> /// This is thrown if the native <c>Multi</c> handle wasn't /// created successfully. /// </exception> public CURLMcode AddHandle(Easy easy) { EnsureHandle(); IntPtr p = easy.GetHandle(); m_htEasy.Add(p, easy); return(External.curl_multi_add_handle(m_pMulti, easy.GetHandle())); }
// called by libcurlshim private static CURLIOERR IoctlDelegate(CURLIOCMD cmd, IntPtr parm) { GCHandle gch = (GCHandle)parm; Easy easy = (Easy)gch.Target; // let's require all of these to be non-null if (easy == null || easy.m_pfIoctl == null || easy.m_ioctlData == null) { return(CURLIOERR.CURLIOE_UNKNOWNCMD); } return(easy.m_pfIoctl(cmd, easy.m_ioctlData)); }
// called by libcurlshim private static int SSLCtxDelegate(IntPtr ctx, IntPtr parm) { int ok = (int)CURLcode.CURLE_OK; GCHandle gch = (GCHandle)parm; Easy easy = (Easy)gch.Target; if (easy == null) { return(ok); } if (easy.m_pfSSLContext == null) { return(ok); // keep going } SSLContext context = new SSLContext(ctx); return((int)easy.m_pfSSLContext(context, easy.m_sslContextData)); }
// called by libcurlshim private static int DebugDelegate(CURLINFOTYPE infoType, IntPtr msgBuf, int msgBufSize, IntPtr parm) { GCHandle gch = (GCHandle)parm; Easy easy = (Easy)gch.Target; if (easy == null) { return(0); } if (easy.m_pfDebug == null) { return(0); } String message = Marshal.PtrToStringAnsi(msgBuf, msgBufSize); easy.m_pfDebug(infoType, message, easy.m_debugData); return(0); }
// called by libcurlshim private static int ProgressDelegate(IntPtr parm, double dlTotal, double dlNow, double ulTotal, double ulNow) { GCHandle gch = (GCHandle)parm; Easy easy = (Easy)gch.Target; if (easy == null) { return(0); } if (easy.m_pfProgress == null) { return(0); } int nprog = easy.m_pfProgress(easy.m_progressData, dlTotal, dlNow, ulTotal, ulNow); return(nprog); }
private Easy(Easy from) { m_pCURL = External.curl_easy_duphandle(from.m_pCURL); EnsureHandle(); m_pMyStrings = External.curl_shim_alloc_strings(); m_pfWrite = null; m_privateData = null; m_writeData = null; m_pfRead = null; m_readData = null; m_pfProgress = null; m_progressData = null; m_pfDebug = null; m_debugData = null; m_pfHeader = null; m_headerData = null; m_pfSSLContext = null; m_sslContextData = null; m_pfIoctl = null; m_ioctlData = null; InstallDelegates(); }
// called by libcurlshim private static int WriteDelegate(IntPtr buf, int sz, int nmemb, IntPtr parm) { int bytes = sz * nmemb; byte[] b = new byte[bytes]; for (int i = 0; i < bytes; i++) { b[i] = Marshal.ReadByte(buf, i); } GCHandle gch = (GCHandle)parm; Easy easy = (Easy)gch.Target; if (easy == null) { return(0); } if (easy.m_pfWrite == null) { return(bytes); // keep going } return(easy.m_pfWrite(b, sz, nmemb, easy.m_writeData)); }
internal MultiInfo(CURLMSG msg, Easy easy, CURLcode result) { m_msg = msg; m_easy = easy; m_result = result; }