Пример #1
0
        /// <summary> Constructor for making SocketChannel objects from connections
        /// made to a ServerSocket.
        ///
        /// </summary>

        public SocketChannel(Interp interp, System.Net.Sockets.TcpClient s)
        {
            this.mode = TclIO.RDWR;
            this.sock = s;

            ChanName = TclIO.getNextDescriptor(interp, "sock");
        }
Пример #2
0
        /// <summary> Open a file with the read/write permissions determined by modeFlags.
        /// This method must be called before any other methods will function
        /// properly.
        ///
        /// </summary>
        /// <param name="interp">currrent interpreter.
        /// </param>
        /// <param name="fileName">the absolute path or name of file in the current
        /// directory to open
        /// </param>
        /// <param name="modeFlags">modes used to open a file for reading, writing, etc
        /// </param>
        /// <returns> the channelId of the file.
        /// </returns>
        /// <exception cref=""> TclException is thrown when the modeFlags try to open
        /// a file it does not have permission for or if the
        /// file dosent exist and CREAT wasnt specified.
        /// </exception>
        /// <exception cref=""> IOException is thrown when an IO error occurs that was not
        /// correctly tested for.  Most cases should be caught.
        /// </exception>

        internal string open(Interp interp, string fileName, int modeFlags)
        {
            mode = modeFlags;
            System.IO.FileInfo fileObj    = FileUtil.getNewFileObj(interp, fileName);
            FileMode           fileMode   = 0;
            FileAccess         fileAccess = 0;

            if (((modeFlags & TclIO.CREAT) != 0) && ((modeFlags & TclIO.EXCL) != 0))
            {
                fileMode = FileMode.CreateNew;
            }
            else if ((modeFlags & TclIO.CREAT) != 0)
            {
                fileMode = FileMode.Create;
            }
            else
            {
                fileMode = FileMode.Open;
            }
            if ((modeFlags & TclIO.TRUNC) != 0)
            {
                fileMode = fileMode & FileMode.Truncate;
            }
            if ((modeFlags & TclIO.APPEND) != 0)
            {
                fileMode = fileMode & FileMode.Append;
            }

            if ((modeFlags & TclIO.RDWR) != 0)
            {
                fileAccess = FileAccess.ReadWrite;
            }
            else if ((modeFlags & TclIO.RDONLY) != 0)
            {
                fileAccess = FileAccess.Read;
            }
            else if ((modeFlags & TclIO.WRONLY) != 0)
            {
                fileAccess = FileAccess.Write;
            }
            else
            {
                throw new TclRuntimeError("FileChannel.java: invalid mode value");
            }

            file = new FileStream(fileObj.FullName, fileMode, fileAccess, FileShare.ReadWrite);

            string fName = TclIO.getNextDescriptor(interp, "file");

            ChanName = fName;
            //Console.Out.WriteLine("",file.Name);
            return(fName);
        }
Пример #3
0
        /// <summary> Constructor - creates a new SocketChannel object with the given
        /// options. Also creates an underlying Socket object, and Input and
        /// Output Streams.
        ///
        /// </summary>

        public SocketChannel(Interp interp, int mode, string localAddr, int localPort, bool async, string address, int port)
        {
            System.Net.IPAddress localAddress = null;
            System.Net.IPAddress addr         = null;

            if (async)
            {
                throw new TclException(interp, "Asynchronous socket connection not " + "currently implemented");
            }

            // Resolve addresses
            if (!localAddr.Equals(""))
            {
                try
                {
                    localAddress = System.Net.Dns.GetHostByName(localAddr).AddressList[0];
                }
                catch (System.Exception e)
                {
                    throw new TclException(interp, "host unknown: " + localAddr);
                }
            }

            try
            {
                addr = System.Net.Dns.GetHostByName(address).AddressList[0];
            }
            catch (System.Exception e)
            {
                throw new TclException(interp, "host unknown: " + address);
            }


            // Set the mode of this socket.
            this.mode = mode;

            // Create the Socket object

//			if ((localAddress != null) && (localPort != 0))
//			{
//
//				sock = new Socket(addr, port, localAddress, localPort);
//			}
//			else
            sock = new System.Net.Sockets.TcpClient(addr.ToString(), port);

            // If we got this far, then the socket has been created.
            // Create the channel name
            ChanName = TclIO.getNextDescriptor(interp, "sock");
        }