예제 #1
0
파일: Socket.cs 프로젝트: liulilittle/nsjs
 private static void Receive(IntPtr info)
 {
     InternalReceive(info, false, (callmode, socket, data, buffer, ofs, count, flags, remoteep) =>
     {
         int len = 0;
         if (callmode == 0)
         {
             SocketExtension.Receive(socket, buffer, 0, count, flags, out len);
         }
         else if (callmode == 1)
         {
             if (SocketExtension.Receive(socket, buffer, ofs, count, flags, out len))
             {
                 for (int i = ofs; i < len; i++)
                 {
                     data[i] = buffer[i];
                 }
             }
         }
         else
         {
             throw new NotSupportedException("callmode");
         }
         return(len);
     });
 }
예제 #2
0
 private string ReadString(int len)
 {
     lock (_signal)
     {
         if (!_socket.Connected || SocketExtension.CleanedUp(_socket))
         {
             return(null);
         }
     }
     byte[] buffer;
     if (!SocketExtension.Receive(_socket, 3, out buffer))
     {
         return(null);
     }
     if (buffer == null)
     {
         return(null);
     }
     return(Encoding.UTF8.GetString(buffer));
 }