@@ -27,17 +27,15 @@ cdef class Channel:
27
27
28
28
def __cinit__ (self , Session session ):
29
29
self .session = session
30
+ self .closed = False
30
31
31
32
def __dealloc__ (self ):
32
33
if self ._channel is not NULL :
34
+ if not self .closed:
35
+ c_ssh.ssh_channel_close(self ._channel)
33
36
c_ssh.ssh_channel_free(self ._channel)
34
37
self ._channel = NULL
35
38
36
- @property
37
- def session (self ):
38
- """ The originating session for this channel."""
39
- return self .session
40
-
41
39
@staticmethod
42
40
cdef Channel from_ptr(c_ssh.ssh_channel _chan, Session session):
43
41
cdef Channel chan = Channel.__new__ (Channel, session)
@@ -46,8 +44,12 @@ cdef class Channel:
46
44
47
45
def close (self ):
48
46
cdef int rc
47
+ if self .closed:
48
+ return 0
49
49
with nogil:
50
50
rc = c_ssh.ssh_channel_close(self ._channel)
51
+ if rc == 0 :
52
+ self .closed = True
51
53
return handle_ssh_error_codes(rc, self .session._session)
52
54
53
55
def get_exit_status (self ):
@@ -144,7 +146,7 @@ cdef class Channel:
144
146
self ._channel, timeout, is_stderr)
145
147
return handle_ok_error_codes(rc)
146
148
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 ):
148
150
cdef int rc
149
151
cdef bytes buf = b' '
150
152
cdef char * cbuf
@@ -161,7 +163,7 @@ cdef class Channel:
161
163
free(cbuf)
162
164
return handle_ok_error_codes(rc), buf
163
165
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 ):
165
167
cdef int rc
166
168
cdef bytes buf = b' '
167
169
cdef char * cbuf
@@ -180,7 +182,7 @@ cdef class Channel:
180
182
return handle_ok_error_codes(rc), buf
181
183
182
184
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 ):
184
186
cdef int rc
185
187
cdef bytes buf = b' '
186
188
cdef char * cbuf
0 commit comments