Exemplo n.º 1
0
 //送信
 bool Send(SockTcp sock,byte[] sendBuf)
 {
     var c = sock.SendUseEncode(sendBuf);
     if(c == sendBuf.Length) {
         sendBuf = new byte[0];
     } else {
         return false;
     }
     return true;
 }
Exemplo n.º 2
0
            //public bool Send(SockTcp tcpObj,bool encode,ref bool life){
            public bool Send(SockTcp tcpObj,bool encode,ILife iLife)
            {
                if(_kindBuf == KindBuf.Memory) {
                    if(encode) {
                        if(-1 == tcpObj.SendUseEncode(_doc))
                            return false;
                    } else {
                        if(-1 == tcpObj.SendNoEncode(_doc))
                            return false;
                    }
                } else {
                    using(var fs = new FileStream(_fileName,FileMode.Open,FileAccess.Read,FileShare.ReadWrite)) {
                        using(var br = new BinaryReader(fs)) {
                            fs.Seek(_rangeFrom,SeekOrigin.Begin);
                            var start = _rangeFrom;
                            while(iLife.IsLife()) {
                                long size = _rangeTo - start + 1;
                                if(size > 1048560)
                                    size = 1048560;
                                if(size <= 0)
                                    break;
                                _doc = new byte[size];
                                int len = br.Read(_doc,0,(int)size);
                                if(len <= 0)
                                    break;

                                if(len != size) {
                                    var tmp = new byte[len];
                                    Buffer.BlockCopy(_doc,0,tmp,0,len);
                                    _doc = tmp;
                                }

                                if(encode) {
                                    if(-1 == tcpObj.SendUseEncode(_doc)) {
                                        return false;
                                    }
                                } else {
                                    if(-1 == tcpObj.SendNoEncode(_doc)) {
                                        return false;
                                    }
                                }
                                start += _doc.Length;
                                if(_rangeTo - start <= 0)
                                    break;
                                Thread.Sleep(1);
                            }
                            br.Close();
                        }
                        fs.Close();
                    }
                }
                return true;
            }
Exemplo n.º 3
0
        //���M
        //count �{���̍s���i-1�̂Ƃ��͑S���j
        public bool Send(SockTcp sockTcp, int count)
        {
            try {
                _header.ForEach(s => sockTcp.SendUseEncode(Encoding.ASCII.GetBytes(s)));

                sockTcp.SendUseEncode(Encoding.ASCII.GetBytes("\r\n"));//��؂�s

                if (count == -1) {
                    _body.ForEach(d => sockTcp.SendUseEncode(d));
                } else {
                    for (int i = 0; i < count && i < _body.Count; i++) {
                        sockTcp.SendUseEncode(_body[i]);
                    }
                }
                return true;
            } catch (Exception ex) {
                //Ver5.9.2
                SetLastError(ex.Message);
                return false;
            }
        }
Exemplo n.º 4
0
 //送信
 bool Send(SockTcp sock, byte[] sendBuf)
 {
     var c = sock.SendUseEncode(sendBuf);
     if (c != sendBuf.Length){
         return false;
     }
     return true;
 }