Skip to content

TCP server is not working #4296

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

Closed
mneumann opened this issue Dec 27, 2012 · 3 comments
Closed

TCP server is not working #4296

mneumann opened this issue Dec 27, 2012 · 3 comments

Comments

@mneumann
Copy link
Contributor

I am trying to write a very simple TCP server (code given below), which just reads from a
socket, but somehow the read() blocks forever. Any idea what I am doing wrong?
I also tried to create a task for each new incoming connection, but the same happens.
I actually found this example on the internet...

When I do "wget http://127.0.0.1:4000/" it prints

  • Server is listening
  • New client
  • Accepted!
  • Unwrapped

and then it blocks forever. I also cannot create new connections at this point.

Best,

Michael

/*
 * Simple TCP server
 */
extern mod std;
use std::net::tcp;
use std::net::ip;
use std::uv;

fn main() {
    tcp::listen(ip::v4::parse_addr("127.0.0.1"), 4000, 100, uv::global_loop::get(),
            |_comm_chan|{
                error!("Server is listening");
            },
            |new_client, _comm_chan|{
              error!("New client");
                let result = tcp::accept(new_client);
                if result.is_ok(){
                    error!("Accepted!");
                    let socket = result::unwrap(move result);
                    error!("Unwrapped");
                    // Now do stuff with this socket
                    let data = socket.read(100); // XXX: This blocks
                    io::println(fmt!("%?", data));
                }else{
                    error!("Not accepted!");
                }
              } */
            });
}
@jesse99
Copy link
Contributor

jesse99 commented Dec 27, 2012

I expect that the socket.read is happening on the same thread as the listen. Try spawning a new task for the connection using a dedicated thread using something like task::spawn_sched(task::ManualThreads(1)).

Likely related to #3599.

@mneumann
Copy link
Contributor Author

Am 27.12.2012 19:09, schrieb Jesse Jones:

I expect that the socket.read is happening on the same thread as the
listen. Try spawning a new task for the connection using a dedicated
thread using something like |task::spawn_sched(task::ManualThreads(1))|.

Thanks, that indeed works, BUT, starting a new native thread for each
connection is very expensive and basically renders libuv useless,
isn't it?

Best,

Michael

@pcwalton
Copy link
Contributor

I think this is a dupe of #3599.

calebcartwright pushed a commit to calebcartwright/rust that referenced this issue Oct 20, 2021
This is a copy of rust-lang#4296 with these changes:
* file is not reopened again to find if the file is generated
* first five lines are scanned for `@generated` marker instead of one
* no attempt is made to only search for marker in comments

`@generated` marker is used by certain tools to understand that the
file is generated, so it should be treated differently than a file
written by a human:
* linters should not be invoked on these files,
* diffs in these files are less important,
* and these files should not be reformatted.

This PR proposes builtin support for `@generated` marker.

I have not found a standard for a generated file marker, but:
* Facebook [uses `@generated` marker](https://tinyurl.com/fb-generated)
* Phabricator tool which was spawned from Facebook internal tool
  [also understands `@generated` marker](https://git.io/JnVHa)
* Cargo inserts `@generated` marker into [generated Cargo.lock files](https://git.io/JnVHP)

My personal story is that rust-protobuf project which I maintain
was broken twice because of incompatibilities/bugs in rustfmt marker
handling: [one](stepancheg/rust-protobuf#493),
[two](stepancheg/rust-protobuf#551).
(Also, rust-protobuf started generating `@generated` marker
[6 years ago](https://git.io/JnV5h)).

While rustfmt AST markers are useful to apply to a certain AST
elements, disable whole-file-at-once all-tools-at-once text level
marker might be easier to use and more reliable for generated code.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants