Beispiel #1
0
        /// <summary>
        ///     SOCKETFUNCTION implementation.
        /// </summary>
        /// <param name="easy"></param>
        /// <param name="sockfd"></param>
        /// <param name="what"></param>
        /// <param name="userp"></param>
        /// <param name="socketp"></param>
        /// <returns></returns>
        private int HandleSocket(IntPtr easy, IntPtr sockfd, CURLpoll what, IntPtr userp, IntPtr socketp)
        {
            Logger.LogTrace(
                $"Called {nameof(CURLMoption.SOCKETFUNCTION)}. We need to poll for {what} on socket {sockfd}.");

            switch (what)
            {
            case CURLpoll.IN:
            case CURLpoll.OUT:
            case CURLpoll.INOUT:
//#if !UNITY
                PollMask events = 0;

                if (what != CURLpoll.IN)
                {
                    events |= PollMask.Writable;
                }
                if (what != CURLpoll.OUT)
                {
                    events |= PollMask.Readable;
                }

                Logger.LogTrace($"Polling socket {sockfd} using libuv with mask {events}.");

                _socketMap.GetOrCreatePoll(sockfd, _loop).Start(events, (poll, status) =>
                {
                    CURLcselect flags = 0;

                    if (status.Mask.HasFlag(PollMask.Readable))
                    {
                        flags |= CURLcselect.IN;
                    }
                    if (status.Mask.HasFlag(PollMask.Writable))
                    {
                        flags |= CURLcselect.OUT;
                    }

                    Logger.LogTrace($"Finished polling socket {sockfd}.");
                    CurlNative.Multi.SocketAction(_multiHandle, sockfd, flags, out int _);
                    CheckMultiInfo();
                });
                break;

            case CURLpoll.REMOVE:
                Logger.LogTrace($"Removing poll of socket {sockfd}.");
                _socketMap.RemovePoll(sockfd);
                break;

//#else
//                    break;
//#endif
            default:
                throw new ArgumentOutOfRangeException(nameof(what));
            }
            return(0);
        }
Beispiel #2
0
 public static extern CURLMcode SocketAction(SafeMultiHandle multiHandle, SafeSocketHandle sockfd,
                                             CURLcselect evBitmask,
                                             out int runningHandles);