Move functions within file without change
Lars Kanis
7 years ago
195 | 195 | return desc->in_gc; |
196 | 196 | } |
197 | 197 | return false; |
198 | } | |
199 | ||
200 | ||
201 | /** | |
202 | * FXRbConvertPtr() is just a wrapper around SWIG_ConvertPtr(). | |
203 | */ | |
204 | ||
205 | void* FXRbConvertPtr(VALUE obj,swig_type_info* ty){ | |
206 | void *ptr; | |
207 | SWIG_ConvertPtr(obj,&ptr,ty,1); | |
208 | return ptr; | |
209 | } | |
210 | ||
211 | ||
212 | // Should we catch exceptions thrown by message handlers? | |
213 | FXbool FXRbCatchExceptions=FALSE; | |
214 | ||
215 | // Returns an FXInputHandle for this Ruby file object | |
216 | FXInputHandle FXRbGetReadFileHandle(VALUE obj,FXuint mode) { | |
217 | int fd; | |
218 | fd = FIX2INT(rb_funcall(obj, rb_intern("fileno"), 0)); | |
219 | #ifdef WIN32 | |
220 | #ifdef __CYGWIN__ | |
221 | return (FXInputHandle) get_osfhandle(fd); | |
222 | #else | |
223 | WSAEVENT hEvent = CreateEvent(NULL, FALSE, FALSE, NULL); | |
224 | long events = 0; | |
225 | if(mode&INPUT_READ) events |= FD_READ|FD_ACCEPT|FD_OOB; | |
226 | if(mode&INPUT_EXCEPT) events |= FD_CLOSE|FD_QOS|FD_GROUP_QOS|FD_ROUTING_INTERFACE_CHANGE|FD_ADDRESS_LIST_CHANGE; | |
227 | if ( WSAEventSelect(_get_osfhandle(fd), hEvent, events) == SOCKET_ERROR ) { | |
228 | WSACloseEvent( hEvent ); | |
229 | rb_raise( rb_eRuntimeError, "WSAEventSelect sockett error: %d", WSAGetLastError() ); | |
230 | } | |
231 | rb_iv_set(obj, "FXRuby::FXRbGetReadFileHandle", ULL2NUM((intptr_t)hEvent)); | |
232 | return (FXInputHandle) hEvent; | |
233 | #endif | |
234 | #else | |
235 | return (FXInputHandle) fd; | |
236 | #endif | |
237 | } | |
238 | ||
239 | void FXRbRemoveReadFileHandle(VALUE obj,FXuint mode) { | |
240 | #ifdef WIN32 | |
241 | WSAEVENT hEvent = (HANDLE)NUM2ULL(rb_iv_get(obj, "FXRuby::FXRbGetReadFileHandle")); | |
242 | CloseHandle( hEvent ); | |
243 | #endif | |
244 | } | |
245 | ||
246 | // Returns an FXInputHandle for this Ruby file object | |
247 | FXInputHandle FXRbGetWriteFileHandle(VALUE obj,FXuint mode) { | |
248 | int fd; | |
249 | #if defined(RUBINIUS) | |
250 | VALUE vwrite = rb_intern("@write"); | |
251 | if(rb_ivar_defined(obj, vwrite)) obj = rb_ivar_get(obj, vwrite); | |
252 | fd = FIX2INT(rb_funcall(obj, rb_intern("fileno"), 0)); | |
253 | #elif defined(RUBY_1_8) | |
254 | OpenFile *fptr; | |
255 | GetOpenFile(obj, fptr); | |
256 | FILE *fpw=GetWriteFile(fptr); | |
257 | fd = fileno(fpw); | |
258 | #else | |
259 | rb_io_t *fptr; | |
260 | GetOpenFile(obj, fptr); | |
261 | VALUE wrio = fptr->tied_io_for_writing; | |
262 | if(wrio) obj = wrio; | |
263 | fd = FIX2INT(rb_funcall(obj, rb_intern("fileno"), 0)); | |
264 | #endif | |
265 | #ifdef WIN32 | |
266 | #ifdef __CYGWIN__ | |
267 | return (FXInputHandle) get_osfhandle(fd); | |
268 | #else | |
269 | WSAEVENT hEvent = CreateEvent(NULL, FALSE, FALSE, NULL); | |
270 | long events = 0; | |
271 | if(mode&INPUT_WRITE) events |= FD_WRITE|FD_CONNECT; | |
272 | if(mode&INPUT_EXCEPT) events |= FD_CLOSE|FD_QOS|FD_GROUP_QOS|FD_ROUTING_INTERFACE_CHANGE|FD_ADDRESS_LIST_CHANGE; | |
273 | if ( WSAEventSelect(_get_osfhandle(fd), hEvent, events) == SOCKET_ERROR ) { | |
274 | WSACloseEvent( hEvent ); | |
275 | rb_raise( rb_eRuntimeError, "WSAEventSelect sockettt error: %d", WSAGetLastError() ); | |
276 | } | |
277 | rb_iv_set(obj, "FXRuby::FXRbGetWriteFileHandle", ULL2NUM((intptr_t)hEvent)); | |
278 | return (FXInputHandle) hEvent; | |
279 | #endif | |
280 | #else | |
281 | return (FXInputHandle) fd; | |
282 | #endif | |
283 | } | |
284 | ||
285 | void FXRbRemoveWriteFileHandle(VALUE obj,FXuint mode) { | |
286 | #ifdef WIN32 | |
287 | WSAEVENT hEvent = (HANDLE)NUM2ULL(rb_iv_get(obj, "FXRuby::FXRbGetWriteFileHandle")); | |
288 | CloseHandle( hEvent ); | |
289 | #endif | |
290 | 198 | } |
291 | 199 | |
292 | 200 | |
1361 | 1269 | } |
1362 | 1270 | |
1363 | 1271 | |
1272 | // Should we catch exceptions thrown by message handlers? | |
1273 | FXbool FXRbCatchExceptions=FALSE; | |
1274 | ||
1275 | ||
1364 | 1276 | // Call the designated function and return its result (which should be a long). |
1365 | 1277 | long FXRbHandleMessage_gvlcb(FXObject* recv,ID func,FXObject* sender,FXSelector key,void* ptr){ |
1366 | 1278 | FXRbHandleArgs hArgs; |
1798 | 1710 | return TRUE; |
1799 | 1711 | } |
1800 | 1712 | |
1713 | /** | |
1714 | * FXRbConvertPtr() is just a wrapper around SWIG_ConvertPtr(). | |
1715 | */ | |
1716 | ||
1717 | void* FXRbConvertPtr(VALUE obj,swig_type_info* ty){ | |
1718 | void *ptr; | |
1719 | SWIG_ConvertPtr(obj,&ptr,ty,1); | |
1720 | return ptr; | |
1721 | } | |
1722 | ||
1723 | ||
1724 | // Returns an FXInputHandle for this Ruby file object | |
1725 | FXInputHandle FXRbGetReadFileHandle(VALUE obj,FXuint mode) { | |
1726 | int fd; | |
1727 | fd = FIX2INT(rb_funcall(obj, rb_intern("fileno"), 0)); | |
1728 | #ifdef WIN32 | |
1729 | #ifdef __CYGWIN__ | |
1730 | return (FXInputHandle) get_osfhandle(fd); | |
1731 | #else | |
1732 | WSAEVENT hEvent = CreateEvent(NULL, FALSE, FALSE, NULL); | |
1733 | long events = 0; | |
1734 | if(mode&INPUT_READ) events |= FD_READ|FD_ACCEPT|FD_OOB; | |
1735 | if(mode&INPUT_EXCEPT) events |= FD_CLOSE|FD_QOS|FD_GROUP_QOS|FD_ROUTING_INTERFACE_CHANGE|FD_ADDRESS_LIST_CHANGE; | |
1736 | if ( WSAEventSelect(_get_osfhandle(fd), hEvent, events) == SOCKET_ERROR ) { | |
1737 | WSACloseEvent( hEvent ); | |
1738 | rb_raise( rb_eRuntimeError, "WSAEventSelect sockett error: %d", WSAGetLastError() ); | |
1739 | } | |
1740 | rb_iv_set(obj, "FXRuby::FXRbGetReadFileHandle", ULL2NUM((intptr_t)hEvent)); | |
1741 | return (FXInputHandle) hEvent; | |
1742 | #endif | |
1743 | #else | |
1744 | return (FXInputHandle) fd; | |
1745 | #endif | |
1746 | } | |
1747 | ||
1748 | void FXRbRemoveReadFileHandle(VALUE obj,FXuint mode) { | |
1749 | #ifdef WIN32 | |
1750 | WSAEVENT hEvent = (HANDLE)NUM2ULL(rb_iv_get(obj, "FXRuby::FXRbGetReadFileHandle")); | |
1751 | CloseHandle( hEvent ); | |
1752 | #endif | |
1753 | } | |
1754 | ||
1755 | // Returns an FXInputHandle for this Ruby file object | |
1756 | FXInputHandle FXRbGetWriteFileHandle(VALUE obj,FXuint mode) { | |
1757 | int fd; | |
1758 | #if defined(RUBINIUS) | |
1759 | VALUE vwrite = rb_intern("@write"); | |
1760 | if(rb_ivar_defined(obj, vwrite)) obj = rb_ivar_get(obj, vwrite); | |
1761 | fd = FIX2INT(rb_funcall(obj, rb_intern("fileno"), 0)); | |
1762 | #elif defined(RUBY_1_8) | |
1763 | OpenFile *fptr; | |
1764 | GetOpenFile(obj, fptr); | |
1765 | FILE *fpw=GetWriteFile(fptr); | |
1766 | fd = fileno(fpw); | |
1767 | #else | |
1768 | rb_io_t *fptr; | |
1769 | GetOpenFile(obj, fptr); | |
1770 | VALUE wrio = fptr->tied_io_for_writing; | |
1771 | if(wrio) obj = wrio; | |
1772 | fd = FIX2INT(rb_funcall(obj, rb_intern("fileno"), 0)); | |
1773 | #endif | |
1774 | #ifdef WIN32 | |
1775 | #ifdef __CYGWIN__ | |
1776 | return (FXInputHandle) get_osfhandle(fd); | |
1777 | #else | |
1778 | WSAEVENT hEvent = CreateEvent(NULL, FALSE, FALSE, NULL); | |
1779 | long events = 0; | |
1780 | if(mode&INPUT_WRITE) events |= FD_WRITE|FD_CONNECT; | |
1781 | if(mode&INPUT_EXCEPT) events |= FD_CLOSE|FD_QOS|FD_GROUP_QOS|FD_ROUTING_INTERFACE_CHANGE|FD_ADDRESS_LIST_CHANGE; | |
1782 | if ( WSAEventSelect(_get_osfhandle(fd), hEvent, events) == SOCKET_ERROR ) { | |
1783 | WSACloseEvent( hEvent ); | |
1784 | rb_raise( rb_eRuntimeError, "WSAEventSelect sockettt error: %d", WSAGetLastError() ); | |
1785 | } | |
1786 | rb_iv_set(obj, "FXRuby::FXRbGetWriteFileHandle", ULL2NUM((intptr_t)hEvent)); | |
1787 | return (FXInputHandle) hEvent; | |
1788 | #endif | |
1789 | #else | |
1790 | return (FXInputHandle) fd; | |
1791 | #endif | |
1792 | } | |
1793 | ||
1794 | void FXRbRemoveWriteFileHandle(VALUE obj,FXuint mode) { | |
1795 | #ifdef WIN32 | |
1796 | WSAEVENT hEvent = (HANDLE)NUM2ULL(rb_iv_get(obj, "FXRuby::FXRbGetWriteFileHandle")); | |
1797 | CloseHandle( hEvent ); | |
1798 | #endif | |
1799 | } | |
1800 | ||
1801 | 1801 | //---------------------------------------------------------------------- |
1802 | 1802 | |
1803 | 1803 | // Copied from the Ruby 1.8.6 sources (signal.c) |