-
Notifications
You must be signed in to change notification settings - Fork 34
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Automatically getting sockets for only single process #38
Comments
As you mentioned yourself, this is how Linux implements it. I understand it might be convenient for a user to get all the sockets for a process, like Another significant reason for not adding something like this to the library is that even when implemented perfectly from the user-space, socket enumeration for a process is a racy operation. At the moment I'm leaning towards adding the implementation as a "sample" tool, so that users can easily re-implement it in their project, while making sure the core library is clean and not opinionated, just like the Linux procfs itself. Created #40 as a possible resolution. WDYT? |
Are you intending to provide "exactly what the kernel provides" or "here's a convenient interface"? The latter can clearly be implemented using the former, the question is does this belong in the library or not? In my mind there's more value in doing both. My opinion is that it should be part of the library, but perhaps not as part of the Some thoughts:
|
Frankly, I added a similar proposal to my previous comment, but decided to remove it later. Mostly because, as I mentioned, there are many possible permutations to what a user might try and achieve. If you think of I understand that this might be useful for users, and I'm trying to balance both here. |
That sounds good to me. I did think about this a bit over the past few days, have you thought about doing a fluent API? In my particular use-case, I am just looking for the processes that have open sockets and where those sockets are connected to. So it could look something like the following(note: these examples assume there is a higher-level
But a more complex use-case could be done too. Here are some ideas on what that could look like:
|
I've spend quite some time, trying to find a solution I'm happy with. Unfortunately, every solution I considered, was still very easy to misuse, and I'll try to explain why. I considered two approaches: 1) adding an orthogonal utilities class and 2) adding a process / nework finder with a functional builder syntax. Both suffer from the same problems. First, I'll say that the functional builder style is very nice:
But, it becomes very error prone and very fast. Problem no. 1: Inconsistency/performance issues due to lack of caching Let's consider the following example:
It looks very innocent, but, in fact, it is not. Every call to Problem no. 2: Values are not captured It becomes even worse when we're considering network enumeration. Let's say, I want to find all the processes with a listening TCP socket. A very nice syntax could be:
But, if you try and list all the sockets of the resulting Problem no. 3: Number of permutations Another problem is the huge number of permutations related to network connections:
Bottom line I am a big fan of APIs that are "easy to use, and very hard to misuse". I will try and figure out a nice and generic solution to implementing "cached" versions of "task" and "net", but I don't think there's going to be an easy solution for that, and I'm not sure if users would need that or not. In the meantime, I will do the following, which should make it much easier for users to search for sockets:
|
Updated the pull request #40. Feel free to let me know what you think :) |
Closing after it seems like we reached an agreement over #40. |
When using
task::get_net
, all of the network sockets that exist are returned, not just the ones for the particular process that we are looking at. I'm not sure if this is intentional or not, since/proc/<task>/net
is the same as/proc/net
. All of the other getters for thetask
class only get data for that particular task.It would be nice if pfs could automatically filter what it returns for each particular process, so that you only get the sockets for the particular task that you are looking at. I do this manually, by checking all of the inode numbers and checking if the socket is used by this process or not based off of the inode number.
The text was updated successfully, but these errors were encountered: