Beispiel #1
0
        /// <summary> int RTMPSockBuf_Fill(RTMPSockBuf *sb)</summary>
        public static int RTMPSockBuf_Fill(RTMPSockBuf sb)
        {
            const string __FUNCTION__ = "RTMPSockBuf_Fill";
            int          nBytes;

            if (sb.sb_size == 0)
            {
                sb.sb_start = 0; // = sb.sb_buf;
            }

            while (true)
            {
                // nBytes = sizeof (sb.sb_buf) - 1 - sb.sb_size - (sb.sb_start - sb.sb_buf);
                nBytes = RTMP.RTMP_BUFFER_CACHE_SIZE - 1 - sb.sb_size - sb.sb_start;
#if CRYPTO_SSL // defined(CRYPTO) && !defined(NO_SSL)
                if (sb.sb_ssl)
                {
                    nBytes = TLS_read(sb.sb_ssl, sb.sb_start + sb.sb_size, nBytes);
                }
                else
#endif
                {
                    //  nBytes = recv(sb.sb_socket, sb.sb_start + sb.sb_size, nBytes, 0);

                    nBytes = sb.sb_socket.Receive(sb.sb_buf, sb.sb_start + sb.sb_size, nBytes, SocketFlags.None);
                }

                if (nBytes != -1)
                {
                    sb.sb_size += nBytes;
                }
                else
                {
                    int       sockerr     = 0; // TODO: GetSockError();
                    const int EINTR       = 2;
                    const int EWOULDBLOCK = 3;
                    const int EAGAIN      = 4;
                    Log.RTMP_Log(Log.RTMP_LogLevel.RTMP_LOGDEBUG, "{0}, recv returned {1}. GetSockError(): {2} ({3})", __FUNCTION__, nBytes, sockerr, string.Empty); // strerror(sockerr)
                    if (sockerr == EINTR && !RTMP.RTMP_ctrlC)
                    {
                        continue;
                    }

                    if (sockerr == EWOULDBLOCK || sockerr == EAGAIN)
                    {
                        sb.sb_timedout = true;
                        nBytes         = 0;
                    }
                }

                break;
            }

            return(nBytes);
        }
Beispiel #2
0
        // int RTMPSockBuf_Close(RTMPSockBuf *sb)
        public static int RTMPSockBuf_Close(RTMPSockBuf sb)
        {
#if CRYPTO_SSL
            if (sb.sb_ssl)
            {
                TLS_shutdown(sb.sb_ssl);
                TLS_close(sb.sb_ssl);
                sb.sb_ssl = NULL;
            }
#endif
            if (sb.sb_socket != null)
            {
                // return closesocket(sb.sb_socket);
                sb.sb_socket.Close();
                return(0);
            }

            return(0);
        }
Beispiel #3
0
        /// <summary> int RTMPSockBuf_Send(RTMPSockBuf *sb, const char *buf, int len) </summary>
        public static int RTMPSockBuf_Send(RTMPSockBuf sb, byte[] buf, int len)
        {
            int rc;

#if _DEBUG
            fwrite(buf, 1, len, netstackdump);
#endif

#if CRYPTO_SSL // defined(CRYPTO) && !defined(NO_SSL)
            if (sb.sb_ssl)
            {
                rc = TLS_write(sb.sb_ssl, buf, len);
            }
            else
#endif
            {
                // rc = send(sb.sb_socket, buf, len, 0);
                rc = sb.sb_socket.Send(buf, 0, len, SocketFlags.None);
            }

            return(rc);
        }