@@ -27,17 +27,15 @@ cdef class Channel:
2727
2828 def __cinit__ (self , Session session ):
2929 self .session = session
30+ self .closed = False
3031
3132 def __dealloc__ (self ):
3233 if self ._channel is not NULL :
34+ if not self .closed:
35+ c_ssh.ssh_channel_close(self ._channel)
3336 c_ssh.ssh_channel_free(self ._channel)
3437 self ._channel = NULL
3538
36- @property
37- def session (self ):
38- """ The originating session for this channel."""
39- return self .session
40-
4139 @staticmethod
4240 cdef Channel from_ptr(c_ssh.ssh_channel _chan, Session session):
4341 cdef Channel chan = Channel.__new__ (Channel, session)
@@ -46,8 +44,12 @@ cdef class Channel:
4644
4745 def close (self ):
4846 cdef int rc
47+ if self .closed:
48+ return 0
4949 with nogil:
5050 rc = c_ssh.ssh_channel_close(self ._channel)
51+ if rc == 0 :
52+ self .closed = True
5153 return handle_ssh_error_codes(rc, self .session._session)
5254
5355 def get_exit_status (self ):
@@ -144,7 +146,7 @@ cdef class Channel:
144146 self ._channel, timeout, is_stderr)
145147 return handle_ok_error_codes(rc)
146148
147- def read (self , c_ssh.uint32_t size = 1024 , bint is_stderr = False ):
149+ def read (self , c_ssh.uint32_t size = 1024 * 1024 , bint is_stderr = False ):
148150 cdef int rc
149151 cdef bytes buf = b' '
150152 cdef char * cbuf
@@ -161,7 +163,7 @@ cdef class Channel:
161163 free(cbuf)
162164 return handle_ok_error_codes(rc), buf
163165
164- def read_nonblocking (self , c_ssh.uint32_t size = 1024 , bint is_stderr = False ):
166+ def read_nonblocking (self , c_ssh.uint32_t size = 1024 * 1024 , bint is_stderr = False ):
165167 cdef int rc
166168 cdef bytes buf = b' '
167169 cdef char * cbuf
@@ -180,7 +182,7 @@ cdef class Channel:
180182 return handle_ok_error_codes(rc), buf
181183
182184 def read_timeout (self , int timeout ,
183- c_ssh.uint32_t size = 1024 , bint is_stderr = False ):
185+ c_ssh.uint32_t size = 1024 * 1024 , bint is_stderr = False ):
184186 cdef int rc
185187 cdef bytes buf = b' '
186188 cdef char * cbuf
0 commit comments