CN105653252A - Method for extending management ability of select model under linux - Google Patents
Method for extending management ability of select model under linux Download PDFInfo
- Publication number
- CN105653252A CN105653252A CN201410674024.5A CN201410674024A CN105653252A CN 105653252 A CN105653252 A CN 105653252A CN 201410674024 A CN201410674024 A CN 201410674024A CN 105653252 A CN105653252 A CN 105653252A
- Authority
- CN
- China
- Prior art keywords
- file descriptor
- self
- customized
- clearing
- grand
- Prior art date
- Legal status (The legal status is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the status listed.)
- Withdrawn
Links
Abstract
The invention discloses a method for extending management ability of a select model in a linux operation system. The method comprises the steps that a file descriptor set data structure fd_set is customized; the data structure supports over 32 int element data members in the file descriptor set; a fd_set defined by the system is replaced by the customized fd_set; a zero clearing macro is customized, and the macro is compatible to the customized fd_set; and then a zero clearing macro defined by the system is replaced by the customized zero clearing macro. The method disclosed by the invention is characterized in that management of over 1023 file descriptors can be supported; a file descriptor management model of primary codes does not need to be altered; and kernel codes do not need to be recompiled.
Description
Technical field
The present invention relates to the communications field, particularly relate to the method for the managerial ability expanding select model in a kind of linux operating system.
Background technology
In software design, how managing multifile descriptor is that we want frequent problems faced, particularly when relating to the network programming based on TCP/IP, it is necessary to managed by the IO of multiple communication links by file descriptor. Usual (SuSE) Linux OS provides the file descriptor management models such as select, poll, epoll, and user can be convenient to use various model and be managed by multifile descriptor.
Being managed by file descriptor it is well known that all employ select model in a lot of software, this kind of model can meet the regulatory requirement that file descriptor is not more than 1023. If but the function of software changes, it is necessary to when can manage the file descriptor being greater than 1023, we generally have two kinds of methods: manage population size by again compiling kernel adjustment select; Or amendment file descriptor management model.
If again compiling kernel, will there is risk in the versatility of code platform, it is necessary to uses the operating system after compiling again. If amendment file descriptor management model, also a series of problems can be brought: on the one hand, needing the file descriptor Governance framework to original code to modify, so complicated software system take a long time with regard to needs and carry out model refinement, and new code also needs to retest in addition; On the other hand, if all employ select model in multiple module, when certain module being upgraded by poll or epoll model, other multiple function module also needs to carry out code upgrading, because in same process, select model can not coexist with poll or epoll model, and this defect is the natural defect of operating system API.
Summary of the invention
In order to solve the problems of the technologies described above, the present invention proposes to expand in a kind of linux operating system the method for the managerial ability of select model, the method can not revise original text part descriptor management model and function code, and when not needing again to be compiled by kernel, by self-defined data structure cleverly, the simple and quick managerial ability to select model is expanded so that this model meets the regulatory requirement being greater than 1023bit file descriptor.Described method is:
User-defined file descriptor set data structure fd_set, the data member in this data structure supporting document descriptor set is greater than 32 int elements, then with the fd_set of self-defined fd_set replacement system definition;
Self-defined clearing is grand, the fd_set that this grand compatibility is self-defined, and then clearing by self-defined clearing macro substitution system definition is grand.
Preferably, self-defined fd_set can be specific as follows:
Wherein, maxfd is the maximum file descriptor needing to support.
Preferably, the clearing of definition is grand can be specific as follows:
#defineFD_ZERO(p)memset(&sampset,0,sizeof(define_fd_set))��
The present invention utilizes the essence that user space data operate by select model, adopt self-defined data structure, extend the scope of the length of internal memory shared by the reading and writing required for select model, exceptional set, thus reach the object of expansion file descriptor quantity. Tool of the present invention has the following advantages: 1, it is possible to supports the management being greater than the file descriptor of 1023, meets software requirement fast; 2, it is not necessary to the file descriptor management model of amendment original code, saves a large amount of code rewriting work; 3, it is not necessary to kernel code is compiled again, ensure the versatility of operation platform; 4, complete compatible linux32 position and linux64 position.
Accompanying drawing explanation
In order to be illustrated more clearly in the embodiment of the present invention or technical scheme of the prior art, it is briefly described to the accompanying drawing used required in embodiment or description of the prior art below, apparently, accompanying drawing in the following describes is some embodiments of the present invention, for those of ordinary skill in the art, under the prerequisite not paying creative work, it is also possible to obtain other accompanying drawing according to these accompanying drawings.
Fig. 1 is the structure iron of the fd_set of Linux system definition;
Fig. 2 is the structure iron of the fd_set of embodiment of the present invention definition;
Fig. 3 is the network architecture diagram of the UDP link of the embodiment of the present invention.
Embodiment
For making the object of the embodiment of the present invention, technical scheme and advantage clearly, below in conjunction with the accompanying drawing in the embodiment of the present invention, technical scheme in the embodiment of the present invention is clearly and completely described, obviously, described embodiment is the present invention's part embodiment, instead of whole embodiments; It should be noted that, when not conflicting, the embodiment in the application and the feature in embodiment can combine mutually. Based on the embodiment in the present invention, those of ordinary skill in the art, not making other embodiments all obtained under creative work prerequisite, belong to the scope of protection of the invention.
Embodiment: pass through select model management 2000 tunnel UDP link one to one in Linux system
In the present embodiment, select model to be managed the file descriptor being greater than 1023, it is necessary to first relevant data structure is transformed.
Can learn by analyzing linux operating system source code, select model needs 5 parameters: nfds, readfds, writefds, exceptfds, timeout, kernel according to first parameter determine the internal memory length of set, according to second and third, the address of four parameters determine to need the start address of the set of management. The quantity of concrete file descriptor is determined by first parameter nfds, and nfds is that maximum file descriptor maxfd adds 1, as long as extending the scope of nfds, so that it may to expand the managerial ability of select, ensure the compatibility of its function.Such as assume that nfds is 1024, then internal memory length is 1024bit, if nfds expands to the numerical value being greater than 1024, then internal memory length is greater than 1024bit, so that it may think that we manage the I/O event of the file descriptor being greater than 1023. That is the managerial ability of select model is expanded, it is important to the scope of expansion maxfd, and maxfd scope is subject to is the restriction that file descriptor sets closes data structure fd_set.
As shown in Figure 1, fd_set is the array of 32 int elements to the structure iron of the fd_set of Linux system definition, altogether 1024 bit, respectively corresponding 1024 file descriptors. When Select wheel askes set, if certain file descriptor has reading and writing, exceptional case, then the bit position 1 in the set of correspondence, otherwise set to 0. Select returns rear user and uses FD_ISSET to judge all file descriptors successively, if bit position corresponding in corresponding set is set to 1, then represents that this file descriptor has event to trigger.
In order to expand maxfd scope, the self-defined data structure fd_set of the present embodiment, its structure iron is as shown in Figure 2, the maximum file descriptor quantity needed is 2000, then the data member in set is revised as 63 int elements, 2016 bit altogether, it is possible to support the management being not more than the file descriptor of 2016. Self-defined data structure fd_set is as follows:
In addition, the grand FD_ZERO of the clearing in system is defined as follows:
#defineFD_ZERO (p) memset ((p), 0, sizeof (* (p))),
Owing to directly not contacting with file descriptor, therefore also need to revise this grand definition so that it is compatible self-defined fd_set, is specially:
#defineFD_ZERO(p)memset(&sampset,0,sizeof(define_fd_set))��
After above-mentioned transformation, select model just can manage the file descriptor being greater than 1023. As shown in Figure 3, concrete management process is the network architecture of the UDP link of the present embodiment:
1, service end and client terminal create 2000 road UDP links, and service end binds 2000 different ports, and client's side link is to 2000 of service end different ports.
2, client terminal continues to send data to service end.
3, service end definition select reads collection also toward wherein adding the file descriptor created.
Define_fd_setreadSet;
Memset (&readSet, 0, sizeof (define_fd_set)); // use the empty clearly reading collection of memset instead of FD_ZERO
FD_SET (sockFd, &readSet); // add all 2000 file descriptors of udp links created
4, service end is called select function wheel and is ask reading collection.
5, collection event is read in services set process.
One of ordinary skill in the art will appreciate that: all or part of step realizing aforesaid method embodiment can be completed by the hardware that programmed instruction is relevant, aforesaid program can be stored in a computer read/write memory medium, this program, when performing, performs the step comprising aforesaid method embodiment; And aforesaid storage media comprises: ROM, RAM, magnetic disc or CD etc. various can be program code stored medium.
Last it is noted that above embodiment is only in order to illustrate the technical scheme of the present invention, it is not intended to limit; Although with reference to previous embodiment to invention has been detailed description, it will be understood by those within the art that: the technical scheme described in foregoing embodiments still can be modified by it, or wherein part technology feature is carried out equivalent replacement; And these amendments or replacement, do not make the spirit and scope of the essence disengaging various embodiments of the present invention technical scheme of appropriate technical solution.
Claims (3)
- Expanding the method for the managerial ability of select model in 1.linux operating system, described method is:User-defined file descriptor set data structure fd_set, the data member in this data structure supporting document descriptor set is greater than 32 int elements, then with the fd_set of self-defined fd_set replacement system definition;Self-defined clearing is grand, the fd_set that this grand compatibility is self-defined, and then clearing by self-defined clearing macro substitution system definition is grand.
- 2. method according to claim 1, it is characterised in that, self-defined fd_set is specific as follows:Wherein, maxfd is the maximum file descriptor needing to support.
- 3. method according to claim 1, it is characterised in that, self-defined clearing is grand specific as follows:#defineFD_ZERO(p)memset(&sampset,0,sizeof(define_fd_set))��
Priority Applications (1)
Application Number | Priority Date | Filing Date | Title |
---|---|---|---|
CN201410674024.5A CN105653252A (en) | 2014-11-21 | 2014-11-21 | Method for extending management ability of select model under linux |
Applications Claiming Priority (1)
Application Number | Priority Date | Filing Date | Title |
---|---|---|---|
CN201410674024.5A CN105653252A (en) | 2014-11-21 | 2014-11-21 | Method for extending management ability of select model under linux |
Publications (1)
Publication Number | Publication Date |
---|---|
CN105653252A true CN105653252A (en) | 2016-06-08 |
Family
ID=56480259
Family Applications (1)
Application Number | Title | Priority Date | Filing Date |
---|---|---|---|
CN201410674024.5A Withdrawn CN105653252A (en) | 2014-11-21 | 2014-11-21 | Method for extending management ability of select model under linux |
Country Status (1)
Country | Link |
---|---|
CN (1) | CN105653252A (en) |
Cited By (2)
Publication number | Priority date | Publication date | Assignee | Title |
---|---|---|---|---|
CN107179950A (en) * | 2017-06-29 | 2017-09-19 | 努比亚技术有限公司 | A kind of application process processing method, mobile terminal and computer-readable recording medium |
CN108228965A (en) * | 2017-12-06 | 2018-06-29 | 北京物芯科技有限责任公司 | A kind of emulation verification method of storage unit, device and equipment |
Citations (4)
Publication number | Priority date | Publication date | Assignee | Title |
---|---|---|---|---|
US20080313309A1 (en) * | 2007-06-18 | 2008-12-18 | Pradipta Kumar Banerjee | Client-server data transfer control |
CN101393527A (en) * | 2007-09-21 | 2009-03-25 | 米特尔网络公司 | Centralized polling service |
CN101488114A (en) * | 2009-02-18 | 2009-07-22 | 北京飞天诚信科技有限公司 | USB equipment processing method in Linux system |
CN102629202A (en) * | 2012-03-07 | 2012-08-08 | 维图通讯有限公司 | Method for processing embedded multi-module Internet of Things mobile terminal device data system |
-
2014
- 2014-11-21 CN CN201410674024.5A patent/CN105653252A/en not_active Withdrawn
Patent Citations (4)
Publication number | Priority date | Publication date | Assignee | Title |
---|---|---|---|---|
US20080313309A1 (en) * | 2007-06-18 | 2008-12-18 | Pradipta Kumar Banerjee | Client-server data transfer control |
CN101393527A (en) * | 2007-09-21 | 2009-03-25 | 米特尔网络公司 | Centralized polling service |
CN101488114A (en) * | 2009-02-18 | 2009-07-22 | 北京飞天诚信科技有限公司 | USB equipment processing method in Linux system |
CN102629202A (en) * | 2012-03-07 | 2012-08-08 | 维图通讯有限公司 | Method for processing embedded multi-module Internet of Things mobile terminal device data system |
Non-Patent Citations (1)
Title |
---|
雨奇: "select()函数以及FD_ZERO、FD_SET、FD_CLR、FD_ISSET", 《HTTPS://BLOG.CSDN.NET/CSTARBL/ARTICLE/DETAILS/7645298》 * |
Cited By (3)
Publication number | Priority date | Publication date | Assignee | Title |
---|---|---|---|---|
CN107179950A (en) * | 2017-06-29 | 2017-09-19 | 努比亚技术有限公司 | A kind of application process processing method, mobile terminal and computer-readable recording medium |
CN107179950B (en) * | 2017-06-29 | 2020-10-27 | 努比亚技术有限公司 | Application process processing method, mobile terminal and computer readable storage medium |
CN108228965A (en) * | 2017-12-06 | 2018-06-29 | 北京物芯科技有限责任公司 | A kind of emulation verification method of storage unit, device and equipment |
Similar Documents
Publication | Publication Date | Title |
---|---|---|
CN103744709B (en) | patch loading method and device | |
CN105511911B (en) | The generation method and device of system firmware upgrade package | |
CN104714788A (en) | Method and device for automatically generating software installation package | |
CN103092970A (en) | Database operation method and device | |
CN105487907A (en) | Difference package manufacturing method and device | |
CN110716845B (en) | Log information reading method of Android system | |
CN102662688B (en) | A kind of Nor flash update method and device | |
WO2016078263A1 (en) | Upgrading control device and terminal, terminal upgrading method and system, and storage medium | |
CN110929883A (en) | Method and device for supporting FPGA (field programmable gate array) training in TensorFlow | |
CN111124288A (en) | VPD storage management method, device, equipment and readable storage medium | |
CN105260169A (en) | Cross-platform python program transplanting method and device | |
CN103430178A (en) | Method, apparatus and product of data updating | |
CN103645888A (en) | System and method for automatically building operation system | |
CN105653252A (en) | Method for extending management ability of select model under linux | |
CN103560934A (en) | Power line modem production testing method and device | |
CN109558121A (en) | Development approach, device, equipment and the storage medium of interface drive program | |
WO2019041891A1 (en) | Method and device for generating upgrade package | |
CN110806891B (en) | Method and device for generating software version of embedded device | |
CN111694580B (en) | Method and device for upgrading and initializing storage device and electronic device | |
CN107463423B (en) | Verification method, storage medium, electronic device and system depending on package tool | |
CN111930387B (en) | Integration method and device of integration package, electronic equipment and storage medium | |
CN111367512B (en) | Method and device for creating Android library module dependency relationship in application development | |
CN111290765B (en) | Firmware quick burning method, system and storage medium | |
CN104765626A (en) | Firmware program writing method and device | |
CN114218261A (en) | Data query method and device, storage medium and electronic equipment |
Legal Events
Date | Code | Title | Description |
---|---|---|---|
C06 | Publication | ||
PB01 | Publication | ||
C10 | Entry into substantive examination | ||
SE01 | Entry into force of request for substantive examination | ||
WW01 | Invention patent application withdrawn after publication |
Application publication date: 20160608 |
|
WW01 | Invention patent application withdrawn after publication |