コード例 #1
0
        public void SendBuffer(SocketBuffer arg)
        {
            if (!isServerStarted || !haveCheckedPW || arg.buffer == null || arg.buffer.Length == 0)
            {
                return;
            }

            transmitLock.AcquireWriterLock(-1);
            try
            {
                transmitQueue.Enqueue(arg);
            }
            catch (Exception) { }
            finally
            {
                transmitLock.ReleaseWriterLock();
            }

            dataReady.Set();

            if (showMsg)
            {
                Trace.WriteLine(string.Format("{0}-Send Buffer leng- {1}", DateTime.Now.ToString("HH:mm:ss:fff"), arg.buffer.Length));
            }
        }
コード例 #2
0
        private void SendThread(object state)
        {
            try
            {
                Queue workQueue = new Queue();
                while (true)
                {
                    WaitHandle[] handles = new WaitHandle[2];
                    handles[0] = stopEvent;
                    handles[1] = dataReady;
                    int result = WaitHandle.WaitAny(handles);
                    if (result == 0)
                    {
                        break;
                    }
                    else if (isServerStarted)
                    {
                        transmitLock.AcquireWriterLock(-1);
                        try
                        {
                            workQueue.Clear();
                            foreach (var message in transmitQueue)
                            {
                                workQueue.Enqueue(message);
                            }
                            transmitQueue.Clear();
                        }
                        catch (Exception) { }
                        finally
                        {
                            transmitLock.ReleaseWriterLock();
                        }

                        foreach (var message in workQueue)
                        {
                            if (message is ServerMsgArg)
                            {
                                SendMsg(message as ServerMsgArg);
                            }
                            else if (message is SocketBuffer)
                            {
                                SocketBuffer sbf = message as SocketBuffer;
                                sbf.SendBuffer();
                            }
                        }
                    }
                }
            }
            catch (Exception) { }
        }